sync-oneshot 0.1.0

A minimal oneshot channel for synchronous Rust.
Documentation

sync-oneshot

crates.io docs.rs GitHub License Build Status

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.

Sender::send will no block the calling thread.
Receiver::recv will block the calling thread.

Example

use std::time::Duration;

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);

Licence

sync-oneshot is provided under the MIT license.See LICENSE