Skip to content

Dart package which provides sequential future execution with return values.

License

Notifications You must be signed in to change notification settings

rorystephenson/future_queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

future_queue

Dart package which provides sequential future execution with return values.

How it works

Here is a code example which demonstrates how futures are queued:

final futureQueue = FutureQueue<int>(seed: 0);

final result1 = futureQueue.append(
  () => Future.delayed(Duration(seconds: 5), () => 1),
);
final result2 = futureQueue.append(
  () => Future.delayed(Duration(seconds: 1), () => 2),
);

print('result1: ${await result1}');
print('result2: ${await result2}');

Will print:

1
2

Allowing null

Simply set the type of the FutureQueue to a nullable value:

final futureQueue = FutureQueue<int?>(seed: null);

Even though the first future takes 4 seconds longer than the second future.

Error handling

If the future throws an exception it can be caught, as usual, by chaining a catchError on the Future returned by FutureBuilder's append.

About

Dart package which provides sequential future execution with return values.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages