Struct crossbeam_channel::Sender[][src]

pub struct Sender<T>(_);

The sending side of a channel.

Senders can be cloned and shared among multiple threads.

Examples

use std::thread;
use crossbeam_channel as channel;

let (s1, r) = channel::unbounded();
let s2 = s1.clone();

thread::spawn(move || s1.send(1));
thread::spawn(move || s2.send(2));

let msg1 = r.recv().unwrap();
let msg2 = r.recv().unwrap();

assert_eq!(msg1 + msg2, 3);

Methods

impl<T> Sender<T>
[src]

Sends a message into the channel, blocking the current thread if the channel is full.

If called on a zero-capacity channel, this method blocks the current thread until a receive operation appears on the other side of the channel.

Note: s.send(msg) is equivalent to select! { send(s, msg) => {} }.

Examples

use std::thread;
use std::time::Duration;
use crossbeam_channel as channel;

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

thread::spawn(move || s.send(1));

assert_eq!(r.recv(), Some(1));

Returns true if the channel is empty.

Note: zero-capacity channels are always empty.

Examples

use crossbeam_channel as channel;

let (s, r) = channel::unbounded();
assert!(s.is_empty());

s.send(0);
assert!(!s.is_empty());

Returns true if the channel is full.

Note: zero-capacity channels are always full.

Examples

use crossbeam_channel as channel;

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

assert!(!s.is_full());
s.send(0);
assert!(s.is_full());

Returns the number of messages in the channel.

Examples

use crossbeam_channel as channel;

let (s, r) = channel::unbounded();
assert_eq!(s.len(), 0);

s.send(1);
s.send(2);
assert_eq!(s.len(), 2);

If the channel is bounded, returns its capacity.

Examples

use crossbeam_channel as channel;

let (s, _) = channel::unbounded::<i32>();
assert_eq!(s.capacity(), None);

let (s, _) = channel::bounded::<i32>(5);
assert_eq!(s.capacity(), Some(5));

let (s, _) = channel::bounded::<i32>(0);
assert_eq!(s.capacity(), Some(0));

Trait Implementations

impl<T: Send> Send for Sender<T>
[src]

impl<T: Send> Sync for Sender<T>
[src]

impl<T> Drop for Sender<T>
[src]

Executes the destructor for this type. Read more

impl<T> Clone for Sender<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T> Debug for Sender<T>
[src]

Formats the value using the given formatter. Read more

impl<T> Hash for Sender<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl<T> PartialEq for Sender<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> Eq for Sender<T>
[src]

impl<T> PartialEq<Receiver<T>> for Sender<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> UnwindSafe for Sender<T>
[src]

impl<T> RefUnwindSafe for Sender<T>
[src]

impl<T> PartialEq<Sender<T>> for Receiver<T>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.