future_aggregate 1.0.0
future_aggregate: ^1.0.0 copied to clipboard
A library for waiting on multiple futures, returning a record with results.
Future Aggregate #
A small library to provide a simple-looking way (and type safe) to wait multiple Futures at same time, instead of chainning them.
It works as a multiple type-safe option for Future.wait<T>(), since that option only supports one type.
final (name, age) = await FutureAggregate.duo(getUserName(), getUserAge());
Methods #
FutureAggregate.duoFutureAggregate.trioFutureAggregate.quartetFutureAggregate.quintetFutureAggregate.sextetFutureAggregate.septetFutureAggregate.octetFutureAggregate.nonetFutureAggregate.decet
Solved Problem #
In the following code, first will fetch name and then will fetch the age.
final name = await getUserName();
final age = await getUserAge();
Instead we can make it occour concurently with:
final nameFuture = getUserName();
final ageFuture = getUserAge();
final name = await nameFuture;
final age = await ageFuture;
With FutureAggregate we can afford same result with better-lokking code:
final (name, age) = await FutureAggregate.duo(getUserName(), getUserAge());