https://github.com/xamantra/elapsed
Get time elapsed for asynchronous function in a single line of code.
https://github.com/xamantra/elapsed
dart dartlang elapsed elapsed-time library plugin
Last synced: about 1 year ago
JSON representation
Get time elapsed for asynchronous function in a single line of code.
- Host: GitHub
- URL: https://github.com/xamantra/elapsed
- Owner: xamantra
- License: bsd-3-clause
- Created: 2021-02-23T10:54:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-03-13T21:39:13.000Z (over 5 years ago)
- Last Synced: 2025-03-08T05:47:01.203Z (over 1 year ago)
- Topics: dart, dartlang, elapsed, elapsed-time, library, plugin
- Language: Dart
- Homepage: https://pub.dev/packages/elapsed
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README

Get time elapsed for asynchronous function in a single line of code.
## What does this do?
- This package is written as a simplified form of [`Stopwatch`](https://api.dart.dev/stable/2.10.5/dart-core/Stopwatch-class.html) class. *And probably better*.
- Only contains one method which is `elapsed(...)` .
- Only accepts a `Future` that the library will automatically await and record the time elapsed.
- Where `` can be of any type including `` .
- The time elapsed will be returned alongside the actual result of the future.
## **Normal** vs `package:elapsed`
This is how you normally call an API with `http` package.
```dart
var response = await http.get(...);
print(response.body); // prints JSON data response.
```
But with this library, you can do this:
```dart
var data = await elapsed(http.get(...));
print(data.result.body); // prints JSON data response.
print(data.inMilliseconds); // prints time elapsed in milliseconds.
// Also has ".inSeconds" and ".inMinutes"
```
## Comparison
**package:elapsed**
**Stopwatch** class
**manual implementation**
## Types
Of course. Types are supported. Like this:
## Null-safety
```yaml
dependencies:
# ...
elapsed: ^1.2.0 # use this version for null-safety. Requires dart 2.12.0 or Flutter 2.0.0 for flutter.
# OR
elapsed: 1.0.7 # no null-safety. can be used in older version of dart and flutter.
# ...
```
## Disclaimer
This is not an alternative to [`time_elapsed`](https://pub.dev/packages/time_elapsed). This is a very different library.