then<R> method

FutureOr<R> then<R>(
  1. FutureOr<R> onValue(
    1. T value
    ), {
  2. Function? onError,
})

Same as Future.then.

  • Note: it's not possible to implement onError with the same behavior at Future.then, since onError will be called only if this is a Future, and not when it's a T.
  • See asyncTry.

Implementation

FutureOr<R> then<R>(FutureOr<R> Function(T value) onValue,
    {Function? onError}) {
  var self = this;

  if (self is Future<T>) {
    return self.then(onValue, onError: onError);
  } else {
    return onValue(self);
  }
}