Future<T>.microtask constructor

Future<T>.microtask(
  1. FutureOr<T> computation(
      )
    )

    Creates a future containing the result of calling computation asynchronously with scheduleMicrotask.

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

    If calling computation returns a Future, completion of the created future will wait until the returned future completes, and will then complete with the same result.

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

    Implementation

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