onRecvError<T> method
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:
- onRecv - Parent
- onRecvValue - Only handle successful result
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);
}