Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/src/dart_queue_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,12 @@ class Queue {
/// A timeout before processing the next item in the queue
final Duration? timeout;

/// Shoud we process this queue LIFO (last in first out)
/// Should we process this queue LIFO (last in first out)
final bool lifo;

///Should we throw an exception for items still in the Queue when .cancel() is called
final bool supressErrorsOnCancel;

/// The number of items to process at one time
///
/// Can be edited mid processing
Expand Down Expand Up @@ -97,7 +100,14 @@ class Queue {
/// Subsquent calls to [add] will throw.
void cancel() {
for (final item in _nextCycle) {
item.completer.completeError(QueueCancelledException());
if (supressErrorsOnCancel == false)
{
item.completer.completeError(QueueCancelledException());
}
else
{
item.completer.complete();
}
}
_nextCycle.removeWhere((item) => item.completer.isCompleted);
_isCancelled = true;
Expand All @@ -113,7 +123,7 @@ class Queue {
cancel();
}

Queue({this.delay, this.parallel = 1, this.timeout, this.lifo = false});
Queue({this.delay, this.parallel = 1, this.timeout, this.lifo = false, this.supressErrorsOnCancel = false});

/// Adds the future-returning closure to the queue.
///
Expand Down