onRecv<T> method
SelectBuilder<R>
onRecv<T>(
- Receiver<
T> rx, - FutureOr<
R> body(- RecvResult<
T>
- RecvResult<
- Object? tag,
- bool if_()?,
Race a channel receiver - handles both success and error cases.
Waits for any message from the channel (successful value or error). Use this when you need to handle both normal messages and channel errors.
Parameters:
rx
: Receiver to wait onbody
: Function to call with the RecvResulttag
: Optional tag for debuggingif_
: Optional guard condition
Example:
await XSelect.run<String>((s) => s
..onRecv(taskResults, (result) => {
result.valueOrNull != null
? 'Task completed: ${result.valueOrNull}'
: 'Task failed: ${result.errorOrNull}'
})
..onTimeout(Duration(minutes: 1), () => 'Task timeout')
);
See also:
- onRecvValue - Only handle successful result
- onRecvError - Only handle error result
Implementation
SelectBuilder<R> onRecv<T>(
Receiver<T> rx,
FutureOr<R> Function(RecvResult<T>) body, {
Object? tag,
bool Function()? if_,
}) {
_branches.add((RecvBranch<T, R>(rx, body, tag: tag), if_));
return this;
}