execute<P, R> method

Future<R> execute<P, R>(
  1. AsyncTask<P, R> task, {
  2. AsyncExecutorSharedDataInfo? sharedDataInfo,
})

Execute task using this executor.

If task was already submitted the execution will be skipped.

Implementation

Future<R> execute<P, R>(AsyncTask<P, R> task,
    {AsyncExecutorSharedDataInfo? sharedDataInfo}) {
  if (task.wasSubmitted) {
    return task.waitResult();
  }

  if (_closed) {
    throw AsyncExecutorClosedError('Not ready: executor closed.');
  } else if (_closing != null) {
    logger.logWarn('Executing task while closing executor: $task');
  }

  if (!_started) {
    return _executeNotStarted(task, sharedDataInfo);
  } else {
    return _executeAlreadyStarted(task, sharedDataInfo);
  }
}