onSend<T> method

SelectBuilder<R> onSend<T>(
  1. Sender<T> sender,
  2. T value,
  3. FutureOr<R> body(), {
  4. Object? tag,
  5. bool if_()?,
})

Wait for a channel send operation to complete.

Races a send operation on a channel sender. Use this when you need to coordinate sending with other async operations or implement backpressure.

Parameters:

  • sender: Sender to use for the send operation
  • value: Value to send
  • body: Function to call when send completes
  • tag: Optional tag for debugging
  • if_: Optional guard condition

Example:

// Producer with flow control
await XSelect.run<String>((s) => s
  ..onRecvValue(controlChannel, (cmd) => 'Command: $cmd')
  ..onSend(outputChannel, processedData, () => 'Data sent')
  ..onTimeout(Duration(seconds: 10), () => 'Send timeout')
);

Implementation

SelectBuilder<R> onSend<T>(
    Sender<T> sender, T value, FutureOr<R> Function() body,
    {Object? tag, bool Function()? if_}) {
  return onFuture(sender.send(value), (_) => body(), tag: tag, if_: if_);
}