cancel method

void cancel([
  1. Task? task,
  2. String? message
])

Task cancellation. If a specific task is provided, only this task will be cancelled. Otherwise, all tasks registered with the WorkerPool are cancelled.

Implementation

void cancel([Task? task, String? message]) {
  if (task != null) {
    _executing.remove(task);
    _queue.removeWhere((t) => t == task);
    task.cancel(message);
  } else {
    final cancelled = _executing.followedBy(_queue).toList();
    _executing.clear();
    _queue.clear();
    for (var task in cancelled) {
      task.cancel(message);
    }
  }
}