Future constructor - Future - dart:async library (original) (raw)

Future<T>(

  1. FutureOr<T> computation() )

Creates a future containing the result of calling computationasynchronously with Timer.run.

If the result of executing computation throws, the returned future is completed with the error.

If the returned value is itself a Future, completion of the created future will wait until the returned future completes, and will then complete with the same result.

If a non-future value is returned, the returned future is completed with that value.

Implementation

factory Future(FutureOr<T> computation()) {
  _Future<T> result = new _Future<T>();
  Timer.run(() {
    FutureOr<T> computationResult;
    try {
      computationResult = computation();
    } catch (e, s) {
      _completeWithErrorCallback(result, e, s);
      return;
    }
    result._complete(computationResult);
  });
  return result;
}