# [−][src]Function crossbeam::channel::bounded

    pub fn bounded<T>(cap: usize) -> (Sender<T>, Receiver<T>)

Creates a channel of bounded capacity.

This channel has a buffer that can hold at most `cap` messages at a time.

A special case is zero-capacity channel, which cannot hold any messages. Instead, send and receive operations must appear at the same time in order to pair up and pass the message over.

# Panics

Panics if the capacity is greater than `usize::max_value() / 4`.

# Examples

A channel of capacity 1:

    use std::thread;
    use std::time::Duration;
    use crossbeam_channel::bounded;

    let (s, r) = bounded(1);

    // This call returns immediately because there is enough space in the channel.
    s.send(1).unwrap();

    thread::spawn(move || {
        // This call blocks the current thread because the channel is full.
        // It will be able to complete only after the first message is received.
        s.send(2).unwrap();
    });

    thread::sleep(Duration::from_secs(1));
    assert_eq!(r.recv(), Ok(1));
    assert_eq!(r.recv(), Ok(2));

A zero-capacity channel:

    use std::thread;
    use std::time::Duration;
    use crossbeam_channel::bounded;

    let (s, r) = bounded(0);

    thread::spawn(move || {
        // This call blocks the current thread until a receive operation appears
        // on the other side of the channel.
        s.send(1).unwrap();
    });

    thread::sleep(Duration::from_secs(1));
    assert_eq!(r.recv(), Ok(1));

# 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
`+`
  Expand all sections
`-`
  Collapse 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`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)