Function mesh::oneshot

source ยท
pub fn oneshot<T>() -> (OneshotSender<T>, OneshotReceiver<T>)
where T: 'static + Send,
Expand description

Creates a unidirection channel for sending a single value of type T.

The channel is automatically closed after the value is sent. Use this instead of channel when only one value ever needs to be sent to avoid programming errors where the channel is left open longer than necessary. This is also more efficient.

Use OneshotSender::send and OneshotReceiver (directly as a future) to communicate between the ends of the channel.

T must implement MeshField. Most typically this is done by deriving MeshPayload.

Both channel endpoints are initially local to this process, but either or both endpoints may be sent to other processes via a cross-process channel that has already been established.

let (send, recv) = oneshot::<u32>();
send.send(5);
let n = recv.await.unwrap();
assert_eq!(n, 5);