thenOr<R> method

FutureOr<R> thenOr<R>(
  1. R after(
    1. T resolved
    ), {
  2. R onError(
    1. Object error,
    2. StackTrace stackTrace
    )?,
})

Implementation

FutureOr<R> thenOr<R>(R after(T resolved), {R onError(Object error, StackTrace stackTrace)?}) {
  final self = this;
  if (self is Future<T>) {
    final withThen = self.then(after);
    if (onError != null) {
      return withThen.catchError(onError);
    } else {
      return withThen;
    }
  } else {
    try {
      // ignore: unnecessary_cast
      final res = after(self as T);
      return res;
    } catch (e, stack) {
      if (onError != null) {
        return onError(e, stack);
      } else {
        rethrow;
      }
    }
  }
}