std1.0.0-beta-7 SafeC docs

std :: async::channel

Struct std::AsyncChannel

#include <std/async/channel.h> source

generic<T: Send> struct AsyncChannel {
    []T buf;
    unsigned long head;
    unsigned long count;
    int closed;
    struct WaitList senders;
    struct WaitList receivers;
    struct Spinlock lk;
}

A bounded multi-producer, multi-consumer FIFO over a caller's buffer.

Fields

§[]T bufsource
§unsigned long headsource

index of the oldest value

§unsigned long countsource

values in the buffer

§int closedsource
§struct WaitList senderssource

waiting for room

§struct WaitList receiverssource

waiting for a value

Methods

§static struct AsyncChannel<T> new([]T storage)source · definition

A channel holding at most storage.len values.

§struct ChanSend<T> send(T v)source · definition

Future: Ready(1) once 'v' is in the channel, Ready(0) if it's closed.

§struct ChanRecv<T> recv()source · definition

Future: Ready(some(v)) with the oldest value, Ready(null) once the channel is closed and empty.

§int try_send(T v)source · definition

Without waiting: 1 sent, 0 full, -1 closed.

§?T try_recv()source · definition

Without waiting: the oldest value, or null if empty (or closed and empty).

§void close()source · definition

No more sends: pending and future sends get 0, receivers drain what is buffered and then get null.

§void drop()source · definition

Closes it, releases the waiting wakers, and drops the values still buffered. Nothing may use the channel (or a future from it) after.

§int is_closed() constsource · definition
§unsigned long len() constsource · definition
§unsigned long capacity() constsource · definition