enqueue<R> method

  1. @protected
  2. @visibleForTesting
Future<R> enqueue<R>(
  1. TaskBase<R> task
)

Enqueues a task either in the current scope or main queue

Implementation

@protected
@visibleForTesting
Future<R> enqueue<R>(TaskBase<R> task) {
  final parentScope = _getParentScope();
  // If we're inside a task scope, add to the nested queue
  if (parentScope != null) {
    parentScope.add(task);
    processNextTask();
    return task.future;
  } else {
    // Otherwise, add to the main queue
    _queue.add(task);
    scheduleTask();
    return task.future;
  }
}