Skip to main content

Module channel

Module channel 

Source
Expand description

Communication channels.

Use bounded, unbounded and rendezvous to create channels for use across threads in the same process. Use ipc_unbounded to create channels that work across processes.

§Examples

use zng::prelude::*;

let (sender, receiver) = task::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}'")
    }
});
task::spawn(async move {
    match receiver.recv().await {
        Ok(msg) => println!("{msg}"),
        Err(_) => eprintln!("no message in channel and no sender connected"),
    }
});

§Full API

See zng_task::channel for the full API.

Structs§

IpcBytes
Immutable bytes vector that can be can be shared fast over IPC.
IpcBytesCast
Safe bytemuck casting wrapper for IpcBytes.
IpcBytesCastIntoIter
An IpcBytesCast iterator that holds a strong reference to it.
IpcBytesIntoIter
An IpcBytes iterator that holds a strong reference to it.
IpcBytesMut
Represents preallocated exclusive mutable memory that can be converted to IpcBytes.
IpcBytesMutCast
Safe bytemuck casting wrapper for IpcBytesMut.
IpcBytesWriter
Represents an async IpcBytes writer.
IpcBytesWriterBlocking
Represents a blocking IpcBytes writer.
IpcFileHandle
File handle that can be transferred to another process.
IpcReceiver
The receiving end of an IPC channel.
IpcSender
The transmitting end of an IPC channel.
NamedIpcReceiver
Init named IPC connection with another process, the receiver end is in the first process.
NamedIpcSender
Init named IPC connection with another process, the sender end is in the first process.
Receiver
The receiving end of a channel.
Sender
The transmitting end of a channel.
WeakIpcBytes
Weak reference to an in process IpcBytes.

Enums§

ChannelError
Error during channel send or receive.
IpcRead
Async read implementer for IpcReadHandle::read
IpcReadBlocking
Blocking read implementer for IpcReadHandle::read_blocking.
IpcReadHandle
File handle or allocated bytes that can be read after sending to another process.

Traits§

IpcValue
Represents a type that can be an input and output of IPC channels.

Functions§

bounded
Create a channel with a maximum capacity.
ipc_unbounded
Create an unbounded IPC channel.
rendezvous
Create a bounded channel with 0 capacity.
unbounded
Create a channel with no maximum capacity.