onFutureError<T> method

SelectBuilder<R> onFutureError<T>(
  1. Future<T> fut,
  2. FutureOr<R> body(
    1. Object error
    ), {
  3. Object? tag,
  4. bool if_()?,
})

Race a Future, but only handle errors.

Successful completion is ignored. Use for error monitoring or when you want to react only to failure cases.

Example:

await XSelect.run<String>((s) => s
  ..onStream(dataStream, (data) => 'Processing: $data')
  ..onFutureError(backgroundTask(), (error) => 'Task failed: $error')
  ..onTimeout(Duration(seconds: 30), () => 'timeout')
);

See also:

Implementation

SelectBuilder<R> onFutureError<T>(
    Future<T> fut, FutureOr<R> Function(Object error) body,
    {Object? tag, bool Function()? if_}) {
  return onFuture<T>(fut.catchError((Object e) => throw e),
      (_) => throw StateError('onFutureError should not handle success'),
      tag: tag, if_: if_);
}