eve.rt.channel

Cross-thread and cross-fiber communication channels.

This module provides typed channels for safe message passing between concurrent execution contexts. Channels support both bounded (with a maximum capacity) and unbounded operation modes.

Types 2

enumChannelStatus : ubyte

Channel status codes returned by non-blocking operations.

SUCCESS = 0Operation completed successfully.
WOULD_BLOCK = 1Channel is empty (for receive) or full (for send).
CLOSED = 2Channel has been closed.
structChannel(T)

A typed channel for cross-thread/cross-fiber communication.

Channels provide a safe way to pass messages between concurrent execution contexts. They can be bounded (with a maximum capacity) or unbounded.

Example:

auto ch = Channel!int(10);  // bounded channel with capacity 10
ch.send(42);
auto value = ch.receive();
assert(value == 42);

Fields
T[] buffer
size_t head
size_t tail
size_t count
size_t capacity_
bool closed_
Mutex mutex
Condition notEmpty
Condition notFull
Methods
ChannelStatus send(T value) @trustedSend a value into the channel, blocking if the channel is full.
ChannelStatus trySend(T value) @trustedTry to send a value without blocking.
ChannelStatus receive(out T value) @trustedReceive a value from the channel, blocking if empty.
ChannelStatus tryReceive(out T value) @trustedTry to receive a value without blocking.
void close() @trustedClose the channel, preventing further sends.
bool isClosed() @property @trustedCheck if the channel has been closed.
size_t length() @property @trustedGet the current number of items in the channel.
size_t capacity() @property const pure @safe nothrow @nogcGet the maximum capacity of the channel.
bool empty() @property @trustedCheck if the channel is empty.
Constructors
this(size_t capacity)Construct a bounded channel with the specified capacity.

Functions 1

fnChannel!T * channel(T)(size_t capacity)Create a bounded channel with the specified capacity.