elapsed 1.0.2 elapsed: ^1.0.2 copied to clipboard
Get time elapsed for asynchronous function in a single line of code.
Get time elapsed for asynchronous function in a single line of code.
What does this do? #
- The library only contains one method which is
elapsed(...)
. - It accepts a
Future<T>
that the library will automatically await and record the time elapsed. - The time elapsed will be returned alongside the actual result of the future.
- Where
<T>
can be of any type including<void>
. - This package is written as a simplified form of
Stopwatch
class. And probably better.
Normal vs package:elapsed
#
This is how you normally call an API with http
package.
var response = await http.get(...);
print(response.body); // prints JSON data response.
But with this library, you can do this:
var data = await elapsed(http.get(...));
print(data.result.body); // prints JSON data response.
^ These two different codes produce the same output. The difference is that you can do this with elapsed
:
// prints time elapsed in milliseconds.
print(data.result.inMilliseconds);
// Also has ".inSeconds" and ".inMinutes"
That's it! Implemented time elapsed for a future with only 1 line of code -> await elapsed(...)
.
Checkout the example tab for more examples.