The sending side of a channel.
Senders can be cloned and shared among multiple threads.
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);
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) => {} }
.
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.
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.
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.
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.
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));
Executes the destructor for this type. Read more
Performs copy-assignment from source
. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given [Hasher
]. Read more
Feeds a slice of this type into the given [Hasher
]. Read more
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.
This method tests for self
and other
values to be equal, and is used by ==
. Read more
This method tests for !=
.