add<T> method

  1. @override
Future<T> add<T>(
  1. Future<T> closure()
)
override

Adds a Future-returning closure to the queue.

The closure will be executed when its turn comes up in the queue.

Throws a QueueCancelledException if the queue has been cancelled.

Implementation

@override
Future<T> add<T>(Future<T> Function() closure) {
  if (_isCancelled) throw QueueCancelledException();

  final item = _SimpleQueuedFuture<T>(closure);
  _queue.addLast(item);

  // Update peak queue size
  if (_queue.length > metrics.peakQueueSize) {
    metrics.peakQueueSize = _queue.length;
  }

  // Start processing if not already running
  if (!_isProcessing) {
    _startProcessing();
  }

  return item.completer.future;
}