std::sync::mpsc::channel - Rust
Description: API documentation for the Rust `channel` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, channel

# Function std::sync::mpsc::channel 1.0.0 [−] [src]

    pub fn channel<T>() -> (Sender<T>, Receiver<T>)

Creates a new asynchronous channel, returning the sender/receiver halves. All data sent on the `Sender` will become available on the `Receiver` in the same order as it was sent, and no `send` will block the calling thread (this channel has an "infinite buffer", unlike `sync_channel`, which will block after its buffer limit is reached). `recv` will block until a message is available.

The `Sender` can be cloned to `send` to the same channel multiple times, but only one `Receiver` is supported.

If the `Receiver` is disconnected while trying to `send` with the `Sender`, the `send` method will return a `SendError`. Similarly, If the `Sender` is disconnected while trying to `recv`, the `recv` method will return a `RecvError`.

# Examples

    use std::sync::mpsc::channel;
    use std::thread;

    let (sender, receiver) = channel();

    // Spawn off an expensive computation
    thread::spawn(move|| {
        sender.send(expensive_computation()).unwrap();
    });

    // Do some useful work for awhile

    // Let's see what that answer was
    println!("{:?}", receiver.recv().unwrap());Run

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
↑
  Move up in search results
↓
  Move down in search results
↹
  Switch tab
⏎
  Go to active search result
+ / -
  Collapse/expand all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)