then<R extends Object> method

  1. @override
Async<R> then<R extends Object>(
  1. @noFutures R noFutures(
    1. T value
    )
)
override

Implementation

@override
@pragma('vm:prefer-inline')
Async<R> then<R extends Object>(@noFutures R Function(T value) noFutures) {
  // Route through `Async(() async {...})` so a synchronous throw from
  // `noFutures` is captured as an Err on the chain instead of escaping to
  // whoever awaits the resulting Async.
  return Async<R>(() async {
    final result = await value;
    switch (result) {
      case Ok(value: final v):
        return noFutures(v);
      case final Err err:
        throw err;
    }
  });
}