add<T> method
Adds the future-returning closure to the queue.
It will be executed after futures returned by preceding closures have been awaited.
Will throw an exception if the queue has been cancelled.
Implementation
Future<T> add<T>(
Future<T> Function() closure, {
String? tag,
TWPriority priority = TWPriority.middle,
}) {
tag = tag ?? TWQueueHelper.getUniqueId();
final completer = Completer<T>();
_nextCycle.add(
_QueuedFuture<T>(
closure,
completer,
timeout,
tag,
),
priority: priority,
);
_updateRemainingItems();
unawaited(_process());
return completer.future;
}