Expand description
Async channels.
The channel can work across UI tasks and parallel tasks, it can be bounded or unbounded and is MPMC.
This module is a thin wrapper around the flume crate’s channel that just limits the API
surface to only async methods. You can convert from/into that flume channel.
§Examples
use zng_task::{self as task, channel};
let (sender, receiver) = channel::bounded(5);
task::spawn(async move {
task::deadline(5.secs()).await;
if let Err(e) = sender.send("Data!").await {
eprintln!("no receiver connected, did not send message: '{}'", e.0)
}
});
task::spawn(async move {
match receiver.recv().await {
Ok(msg) => println!("{msg}"),
Err(_) => eprintln!("no message in channel and no sender connected"),
}
});Structs§
- Receiver
- The receiving end of a channel.
- Send
Error - An error that may be emitted when attempting to send a value into a channel on a sender when all receivers are dropped.
- Sender
- The transmitting end of a channel.
- Unbound
Sender - The transmitting end of an unbounded channel.
Enums§
- Recv
Error - An error that may be emitted when attempting to wait for a value on a receiver when all senders are dropped and there are no more messages in the channel.
- Recv
Timeout Error - An error that may be emitted when attempting to wait for a value on a receiver with a timeout when the receive operation times out or all senders are dropped and there are no values left in the channel.
- Send
Timeout Error - An error that may be emitted when sending a value into a channel on a sender with a timeout when the send operation times out or all receivers are dropped.
Functions§
- bounded
- Create a channel with a maximum capacity.
- rendezvous
- Create a
boundedchannel with0capacity. - unbounded
- Create a channel with no maximum capacity.