std1.0.0-beta-7 SafeC docs

Module async::channel

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

async: channels (oneshot, bounded MPMC)

Channels whose send and receive are futures: a receiver waiting for a value, or a sender waiting for room, is Pending (with its waker registered) instead of blocking a thread — tokio::sync::oneshot and tokio::sync::mpsc (bounded). They work across executors and threads (every operation takes the channel's spinlock), and allocate nothing: an AsyncChannel's buffer is a slice you provide.

struct Oneshot<int> done = Oneshot::new();
// a task:   AWAIT_INTO(1, self.v, self.rx);    with self.rx = done.recv()
// elsewhere: done.send(42);

int slots[8];
struct AsyncChannel<int> ch = AsyncChannel::new(slots[0..8]);
self.tx = ch.send(7);     AWAIT_INTO(1, self.ok, self.tx);   // 1 sent, 0 closed
self.rx = ch.recv();      AWAIT_INTO(2, self.got, self.rx);  // ?int: null once closed and drained
ch.close();

A channel must stay where it is while futures from send()/recv() exist (they point at it). Send and receive futures are each polled to completion once; make a new one for every value. Dropping a pending send future doesn't send its value.

Structs

OneshotOne value, sent once, received once.
OneshotRecv
AsyncChannelA bounded multi-producer, multi-consumer FIFO over a caller's buffer.
ChanSend
ChanRecv

Macros

ONESHOT_EMPTY
ONESHOT_FULL
ONESHOT_CLOSEDclosed by the sender with no value
ONESHOT_TAKENthe value was received