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

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

    pub fn sync_channel<T>(bound: usize) -> (SyncSender<T>, Receiver<T>)

Creates a new synchronous, bounded channel.

Like asynchronous channels, the `Receiver` will block until a message becomes available. These channels differ greatly in the semantics of the sender from asynchronous channels, however.

This channel has an internal buffer on which messages will be queued. When the internal buffer becomes full, future sends will block waiting for the buffer to open up. Note that a buffer size of 0 is valid, in which case this becomes "rendezvous channel" where each send will not return until a recv is paired with it.

As with asynchronous channels, all senders will panic in `send` if the `Receiver` has been destroyed.

# Examples

    use std::sync::mpsc::sync_channel;
    use std::thread;

    let (tx, rx) = sync_channel(1);

    // this returns immediately
    tx.send(1).unwrap();

    thread::spawn(move|| {
        // this will block until the previous message has been received
        tx.send(2).unwrap();
    });

    assert_eq!(rx.recv().unwrap(), 1);
    assert_eq!(rx.recv().unwrap(), 2);Run

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