rokdocs
v0.1

rok::core::channel

rok::core::channel - message passing between threads (stdlib spec 2.17). Multi-producer, single-consumer; recv / send block the OS thread, recv_async / for await / send_async suspend the task (task::park: receivers on the meta address, senders one past it).

The queue (2.17.6): a bounded channel's is a lock-free ring (Vyukov's MPMC: per-slot stamps, CAS on head / tail), an unbounded one's a list of fixed segments behind its own lock (it grows without copying, and drained segments are dropped). Waiting needs no lock: a waiter counts itself in a wait word (rx / tx) and looks at the queue again before sleeping on it; a push / pop wakes only when someone is counted.

Modules

    Structs

    Sender

    pub struct Sender<T>

    The sending end. Each clone is its own sender and is closed on its own; the channel closes when every sender has closed (2.17.3).

    • pub fn send(self, value: T) throws (SendError<T>)

      Queue value (blocking while a bounded channel is full, and on a rendezvous channel until it is received). Throws it back if this sender was closed.

    • pub fn try_send(self, value: T) throws (TrySendError<T>)

      Queue value without blocking: Full if a bounded channel is full, or if no receiver is waiting on a rendezvous channel.

    • pub const fn send_async(self, value: T) -> SendFuture<T>

      try await tx.send_async(v) inside async code: like send, but suspends the task (not the thread) while a bounded channel is full, and on a rendezvous channel until the value is received.

    • pub fn close(self)

      Close this sender; later sends on it throw Closed.

    Trait implementations 1
    • impl<T> Clone for Sender<T>

    Receiver

    pub struct Receiver<T>

    The receiving end.

    • pub const fn recv_async(self) -> RecvFuture<T>

      await rx.recv_async() inside async code: like recv, but suspends the task instead of blocking the thread.

    • pub fn recv(self) -> T | none

      The next value, blocking until one arrives; none once the queue is empty and every sender has closed.

    • pub fn try_recv(self) -> T | none

      The next value if one is queued; none if empty or closed.

    • pub fn iter(self) -> ChannelIter<T>

      Values until the channel closes (also for v in rx).

    Trait implementations 2
    • impl<T> IntoIterator for Receiver<T>
    • impl<T> rok::core::stream::Stream for Receiver<T>

    ChannelIter

    pub struct ChannelIter<T>
    Trait implementations 1
    • impl<T> Iterator for ChannelIter<T>

    RecvFuture

    pub struct RecvFuture<T>

    Receiver::recv_async.

    Trait implementations 1
    • impl<T> rok::core::future::Future for RecvFuture<T>

    SendFuture

    pub struct SendFuture<T>

    Sender::send_async.

    • pub fn poll(ref self, ref ctx: rok::core::future::Context) throws (SendError<T>) -> rok::core::future::Poll<()>

    Enums

    SendError

    pub enum SendError<T>

    What send hands back when this sender was closed.

    • Closed(T)
    Trait implementations 3
    • impl<T> Display for SendError<T>
    • impl<T> Debug for SendError<T>
    • impl<T> Error for SendError<T>

    TrySendError

    pub enum TrySendError<T>
    • Full(T)
    • Closed(T)
    Trait implementations 3
    • impl<T> Display for TrySendError<T>
    • impl<T> Debug for TrySendError<T>
    • impl<T> Error for TrySendError<T>

    Functions

    channel

    pub const fn channel<T: Send>() -> (Sender<T>, Receiver<T>)

    An unbounded channel.

    channel_bounded

    pub const fn channel_bounded<T: Send>(cap: usize) -> (Sender<T>, Receiver<T>)

    A channel holding at most cap queued values: send blocks while it is full. cap 0 is a rendezvous channel: send returns once a receiver has taken the value.