January 2019
Intermediate to advanced
520 pages
14h 32m
English
The oneshot module implements a channel of a single message. It also has its own Sender and Receiver types, but these work in a different way. The Sender has a send method that completes oneshot and consumes an instance completely. Sender doesn't need to implement the Sink trait, because we can't send multiple items. It has a preallocated cell for an item that will be put into the cell immediately and we don't have any queue.
The Receiver implements the Future trait, which means you have to use a reactor to get an item from it:
fn single() { let (tx_sender, rx_future) = oneshot::channel::<u8>(); let receiver = rx_future.map(|x| { println!("Received: {}", x); }); let sender = tx_sender.send(8); let execute_all = future::join_all(vec![ ...Read now
Unlock full access