Skip to main content

Crate sync_oneshot

Crate sync_oneshot 

Source
Expand description

A minimal oneshot channel for synchronous Rust.

A oneshot channel is used for sending a single message between threads. The channel function is used to create a Sender and Receiver handle pair that form the channel.

  • The Sender handle is used by the producer to send the value.
  • The Receiver handle is used by the consumer to receive the value.

Each handle can be used on other threads.

§Example

let (tx, rx) = sync_oneshot::channel();

std::thread::spawn(move || {
    std::thread::sleep(Duration::from_millis(200));
    tx.send(5).unwrap();
});

// blocking thread until a message available
let val = rx.recv().unwrap();
assert_eq!(val, 5);

Structs§

Receiver
Receive a value from the associated Sender.
RecvError
Error returned by the Receiver::recv.
Sender
Sends a value to the associated Receiver.

Enums§

TryRecvError
Error returned by the try_recv function on Receiver.

Functions§

channel
Creates a new oneshot channel, returning the sender/receiver halves.