cancel method

  1. @override
void cancel()
override

Cancels the queue.

Any unprocessed items will be completed with a QueueCancelledException. Subsequent calls to add will also throw a QueueCancelledException.

Implementation

@override
void cancel() {
  _isCancelled = true;

  // Complete all pending tasks with cancellation error
  while (_queue.isNotEmpty) {
    final item = _queue.removeFirst();
    if (!item.completer.isCompleted) {
      item.completer.completeError(QueueCancelledException());
    }
  }
}