pub struct Channel<T: Marshal> { /* private fields */ }Expand description
Streaming MPMC channel, backed by SharedRing. Use this for
arrival-order queues with multiple producers and multiple
consumers (the canonical request-fanout / result-fanin shape).
The dispatcher confirms SharedRing is the right family for the
caller’s workload shape; if a different family is picked, the
constructor returns ApiError::WrongFamily.
Implementations§
Source§impl<T: Marshal> Channel<T>
impl<T: Marshal> Channel<T>
Sourcepub fn create(
path: impl AsRef<Path>,
shape: MmfWorkloadShape,
capacity: usize,
) -> Result<Self, ApiError>
pub fn create( path: impl AsRef<Path>, shape: MmfWorkloadShape, capacity: usize, ) -> Result<Self, ApiError>
Create a channel at path with the given workload shape.
capacity is the ring slot count (rounded up to next pow2).
Two small adjacent waker files (.cw / .pw) carry the
blocking + async wakeups across processes.
Sourcepub fn open(path: impl AsRef<Path>, capacity: usize) -> Result<Self, ApiError>
pub fn open(path: impl AsRef<Path>, capacity: usize) -> Result<Self, ApiError>
Open an existing channel at path.
Sourcepub fn send(&self, item: &T) -> Result<(), ApiError>
pub fn send(&self, item: &T) -> Result<(), ApiError>
Non-blocking send. Err(Transport(Full)) when the ring is full.
Sourcepub fn recv(&self) -> Result<T, ApiError>
pub fn recv(&self) -> Result<T, ApiError>
Non-blocking recv. Err(Transport(Empty)) when the ring is empty.
Sourcepub fn send_blocking(
&self,
item: &T,
timeout: Option<Duration>,
) -> Result<(), ApiError>
pub fn send_blocking( &self, item: &T, timeout: Option<Duration>, ) -> Result<(), ApiError>
Blocking send: parks the calling thread until space frees up (or
timeout elapses). None waits indefinitely.
Sourcepub fn recv_blocking(&self, timeout: Option<Duration>) -> Result<T, ApiError>
pub fn recv_blocking(&self, timeout: Option<Duration>) -> Result<T, ApiError>
Blocking recv: parks the calling thread until an item arrives (or
timeout elapses). None waits indefinitely.
Sourcepub fn recv_async(&self) -> RecvFut<'_, T> ⓘ
pub fn recv_async(&self) -> RecvFut<'_, T> ⓘ
Async recv. Resolves to the next item, suspending the task while the ring is empty. Spawns a recv reactor on first call so the wake bridges across processes.
Sourcepub fn send_async(&self, item: &T) -> SendFut<'_, T> ⓘ
pub fn send_async(&self, item: &T) -> SendFut<'_, T> ⓘ
Async send. Resolves once the item is in the ring, suspending the task while it is full.