add<T> method

Future<T> add<T>(
  1. Future<T> closure(), {
  2. String? tag,
  3. TWPriority priority = TWPriority.middle,
})

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;
}