Struct std::sync::channel::UnboundedChannel
An unbounded synchronous queue.
Uses Deque as a growable ring buffer and Mutex and CondVar to provide mutual exclusion and signalling.
Sending a value to the UnboundedChannel
will not block (except in the unlikely case of a highly contended
mutex).
Example
use std::sync::channel::UnboundedChannel;
use std::thread::spawn;
let chan: UnboundedChannel<i32> = UnboundedChannel::new();
let t = spawn(|&chan| {
for i in 0..10 {
chan.send(i).unwrap();
}
chan.close();
});
// Prints all the values.
for i in chan {
println!("{}", i);
}
t.join().unwrap();
Run this example
Fields
Methods
impl UnboundedChannel<T> { ... }
-
fn new() -> UnboundedChannel<T>
Creates a new unbounded channel
-
fn shrink_to_fit(self: &mut UnboundedChannel<T>)
Reduces the size of the underlying queue to the number of contained values.
-
fn send(self: &mut UnboundedChannel<T>, value: T) -> Result<(), ChannelError>
-
fn recv(self: &mut UnboundedChannel<T>) -> Result<T, ChannelError>
Receive a value from the channel.
This function will block if the channel is empty.
-
fn try_recv(self: &mut UnboundedChannel<T>) -> Result<T, ChannelError>
Try to receive a value from the channel.
If the channel is empty, this function will return WouldBlock.
-
fn recv_timeout(self: &mut UnboundedChannel<T>, timeout: Duration) -> Result<T, ChannelError>
Try to receive a value from the channel with a timeout.
If the channel is empty, this function will return WouldBlock.
-
fn close(self: &mut UnboundedChannel<T>)
-
fn iter(self: &mut UnboundedChannel<T>) -> ChannelIterator<UnboundedChannel<T>, T>
-
fn free(self: &mut UnboundedChannel<T>)
Frees the memory backing the object.
Mixins
impl UnboundedChannel<T> { ... }
-
mixin ConditionExt<UnboundedChannel<T>>