Module zng_task::channel

source ·
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§

  • The receiving end of a channel.
  • An error that may be emitted when attempting to send a value into a channel on a sender when all receivers are dropped.
  • The transmitting end of a channel.
  • The transmitting end of an unbounded channel.

Enums§

  • 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.
  • 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.
  • 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§