ifAsync method

  1. @override
Async<T> ifAsync(
  1. @noFutures void noFutures(
    1. Async<T> self,
    2. Async<T> async
    )
)
override

Performs a side-effect if this is Async.

Implementation

@override
@pragma('vm:prefer-inline')
Async<T> ifAsync(
  @noFutures void Function(Async<T> self, Async<T> async) noFutures,
) {
  // Callback is `void` + `@noFutures`, so we run it inline and absorb any
  // throw onto the returned `Async`. `on Err catch` preserves a user-thrown
  // `Err` verbatim — wrapping it would lose statusCode/breadcrumbs.
  try {
    noFutures(this, this);
    return this;
  } on Err catch (err) {
    return Async.err(err.transfErr<T>());
  } catch (error, stackTrace) {
    return Async.err(Err<T>(error, stackTrace: stackTrace));
  }
}