xur_

> module

std::sync

channels for sending values between threads

use std::sync; in the browser

std::sync provides channels for inter-thread communication. channel() returns a (Sender, Receiver) pair.

> functions

# channel() -> (Sender, Receiver)

Creates a channel. Values sent are received in order. Copies of the Sender (such as ones captured by several threads) all send to the same Receiver.

> types

┌ type Receiver

The receiving half of a channel.

# receiver.recv() -> Option<T>

Waits for the next value. Returns None once every sender is gone and nothing is left to receive.

# receiver.try_recv() -> Option<T>

The next value if one is waiting, otherwise None without waiting.

┌ type Sender

The sending half of a channel. Copies of it send to the same receiver.

# sender.send(value: T) -> Result<(), str>

Sends value without waiting. Returns Err if the receiver is gone.

> examples

use std::sync;
use std::thread;
use std::io;

fn main() {
    let (tx, rx) = sync::channel();
    thread::spawn(|| {
        tx.send("hello from another thread").unwrap();
    });
    io::println("{}", rx.recv().unwrap());
}