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

Structs§

IpcBytes
Immutable bytes vector that can be can be shared fast over IPC.
IpcBytesCast
Safe bytemuck casting wrapper for IpcBytes.
IpcBytesMut
Represents preallocated exclusive mutable memory for a new IpcBytes.
IpcBytesMutCast
Safe bytemuck casting wrapper for IpcBytesMut.
IpcBytesWriter
Represents an async IpcBytes writer.
IpcBytesWriterBlocking
Represents a blocking IpcBytes writer.
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.

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.
is_ipc_serialization
Checks if is inside with_ipc_serialization.
rendezvous
Create a bounded channel with 0 capacity.
unbounded
Create a channel with no maximum capacity.
with_ipc_serialization
Enables special serialization of memory mapped files for the serialize call.