# Function std::sync::mpsc::channel [−] [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, and no send will block the calling thread (this channel has an "infinite buffer").

# Examples

fn main() { use std::sync::mpsc::channel; use std::thread; // tx is the sending half (tx for transmission), and rx is the receiving // half (rx for receiving). let (tx, rx) = channel(); // Spawn off an expensive computation thread::spawn(move|| { fn expensive_computation() {} tx.send(expensive_computation()).unwrap(); }); // Do some useful work for awhile // Let's see what that answer was println!("{:?}", rx.recv().unwrap()); }

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

    // tx is the sending half (tx for transmission), and rx is the receiving
    // half (rx for receiving).
    let (tx, rx) = channel();

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

    // Do some useful work for awhile

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

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## 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`)