nbchan

Module oneshot

Source
Expand description

Oneshot channel.

The sender of a oneshot channel can send at most one message to the corresponding receiver.

§Examples

use std::thread;
use nbchan::oneshot::{self, TryRecvError};

let (tx, mut rx) = oneshot::channel();

// Sender
thread::spawn(|| { tx.send(10).unwrap(); });

// Receiver
loop {
    match rx.try_recv() {
        Ok(v) => {
            assert_eq!(v, 10);
            break;
        }
        Err(e) => {
            assert_eq!(e, TryRecvError::Empty);
        }
    }
 }

Re-exports§

Structs§

  • The receiving-half of an asynchronous oneshot channel.
  • The sending-half of an asynchronous oneshot channel.

Functions§

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