Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nivisi/delayed_future
⏳ A Dart extension that allows to delay your Futures.
https://github.com/nivisi/delayed_future
async async-await dart dart-future dartlang delay flutter future package plugin
Last synced: about 1 month ago
JSON representation
⏳ A Dart extension that allows to delay your Futures.
- Host: GitHub
- URL: https://github.com/nivisi/delayed_future
- Owner: nivisi
- License: mit
- Created: 2023-01-19T16:20:06.000Z (almost 2 years ago)
- Default Branch: develop
- Last Pushed: 2023-01-21T08:48:43.000Z (almost 2 years ago)
- Last Synced: 2024-09-29T16:05:20.874Z (about 1 month ago)
- Topics: async, async-await, dart, dart-future, dartlang, delay, flutter, future, package, plugin
- Language: Dart
- Homepage: https://pub.dev/packages/delayed_future
- Size: 9.77 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
# delayed_future [![pub version][pub-version-img]][pub-version-url]
⏳ A Dart extension that allows to delay your Futures.
## Why?
Sometimes it makes sense to delay your futures. For example, if you're making an API call and showing a loader. The response might come too quick fast.
By making sure that the execution will run for at least a little, like 350 ms, we'll make the loader more noticeable and the UX more convenient.
## How to use
### Install the package
Add the dependency to **pubspec.yaml**:
```
dependencies:
delayed_future: ^1.0.3
```### Use it!
```dart
// This will use default values from the config.
await anyFuture().delayResult();await anotherFuture().delayResult(
// Custom duration!
duration: const Duration(milliseconds: 150),// If throwImmediatelyOnError is true and `anotherFuture` throws an exception,
// the execution will fail immediately.
// Otherwise it will run for at least the given time.
throwImmediatelyOnError: true,
);// Or use it directly on a function
await anyFuture.delayCall();
await anotherFuture.delayCall(Duration(milliseconds: 500));
```### Set the default values
You can change the default values of `duration` and `throwImmediatelyOnError` like this:
```dart
DelayedFuture.duration = const Duration(milliseconds: 500);
DelayedFuture.throwImmediatelyOnError = true;
```[pub-version-img]: https://img.shields.io/badge/pub-v1.0.3-0175c2?logo=dart
[pub-version-url]: https://pub.dev/packages/delayed_future