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.
- IpcBytes
Cast - Safe bytemuck casting wrapper for
IpcBytes. - IpcBytes
Cast Into Iter - An
IpcBytesCastiterator that holds a strong reference to it. - IpcBytes
Into Iter - An
IpcBytesiterator that holds a strong reference to it. - IpcBytes
Mut - Represents preallocated exclusive mutable memory that can be converted to
IpcBytes. - IpcBytes
MutCast - Safe bytemuck casting wrapper for
IpcBytesMut. - IpcBytes
Writer - Represents an async
IpcByteswriter. - IpcBytes
Writer Blocking - Represents a blocking
IpcByteswriter. - IpcFile
Handle - 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.
- Named
IpcReceiver - Init named IPC connection with another process, the receiver end is in the first process.
- Named
IpcSender - 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.
- Weak
IpcBytes - Weak reference to an in process
IpcBytes.
Enums§
- Channel
Error - Error during channel send or receive.
- IpcRead
- Async read implementer for
IpcReadHandle::read - IpcRead
Blocking - Blocking read implementer for
IpcReadHandle::read_blocking. - IpcRead
Handle - 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
boundedchannel with0capacity. - unbounded
- Create a channel with no maximum capacity.