onRecvError<T> method

SelectBuilder<R> onRecvError<T>(
  1. Receiver<T> rx,
  2. FutureOr<R> body(
    1. RecvError error
    ), {
  3. Object? tag,
  4. bool if_()?,
})

Race a channel receiver - only handle error messages.

Waits for error conditions from the channel, ignoring successful values. Use for error monitoring and handling failure conditions.

Example:

await XSelect.run<String>((s) => s
  ..onStream(dataStream, (data) => 'Processing: $data')
  ..onRecvError(errorChannel, (error) => 'Error detected: $error')
  ..onTimeout(Duration(minutes: 1), () => 'All systems normal')
);

See also:

Implementation

SelectBuilder<R> onRecvError<T>(
    Receiver<T> rx, FutureOr<R> Function(RecvError error) body,
    {Object? tag, bool Function()? if_}) {
  return onRecv<T>(rx, (result) {
    if (result.hasError) {
      return body(result.error);
    }
    return Future<R>.error(StateError('Unexpected RecvResult: $result'));
  }, tag: tag, if_: if_ ?? () => !rx.isDisconnected);
}