final asyncQ = AsyncQueue();
asyncQ.addQueueListener((event) => print("$event"));
Await job result (v3.0.0+)
addJob returns a Future that completes with the job's return value. This works alongside previousResult — they serve different purposes.
final q = AsyncQueue.autoStart();
// Each addJob returns a Future you can await for its resultfinal userFuture = q.addJob((_) async {
returnawait api.getUser(); // returns "Sam"
});
// previousResult still chains between jobsfinal postsFuture = q.addJob((previousResult) async {
returnawait api.getPostsFor(previousResult);
});
final user = await userFuture; // "Sam"final posts = await postsFuture; // [Post, Post, ...]
Automatic retry on exceptions (v3.0.0+)
Jobs that throw are automatically retried up to retryTime times. You no longer need to catch errors and call retry() manually (though you still can for custom logic).
q.addJob((_) async {
// if this throws, it will be retried automaticallyreturnawait api.fetchData();
}, retryTime: 3);
onError callback (v3.0.0+)
Handle errors at the queue level without parsing events:
This package would be useful if you have multiple widgets in a screen or even in multiple screens that need to do some async requests that are related to each other.
For examples:
To make one request from a widget wait for another request from another widget to finish.
To avoid multiple requests from the front end hitting the backend in a short time, which would confuse the backend.