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.
Warning: This module contains blocking operations (blockingSend, blockingReceive) that use mutex-based waiting. Never call blocking operations from an event-loop thread — they will block the entire loop and cause deadlocks or latency spikes.
For event-loop-safe usage, use the non-blocking variants:
trySend— returns immediately withWOULD_BLOCKif fulltryReceive— returns immediately withWOULD_BLOCKif empty
Example (correct usage from worker thread):
// Worker thread — blocking is OK here
auto ch = channel!int(10);
ch.blockingSend(42); // Blocks until space available
// Event loop thread — use non-blocking only!
if (ch.trySend(value) == ChannelStatus.WOULD_BLOCK) {
// Handle backpressure without blocking the loop
}Types 2
Channel status codes returned by non-blocking operations.
Retryability and Fatality Guide:
OK— Success, no retry neededWOULD_BLOCK— Retryable after data is available or space is freedCLOSED— Fatal, channel cannot be reused
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.
Important: Channels have both blocking and non-blocking operations:
blockingSend/blockingReceive— block the thread, unsafe for event loopstrySend/tryReceive— return immediately, safe for event loops
Example (non-blocking, event-loop safe):
auto ch = channel!int(10); // bounded channel with capacity 10
// Non-blocking send (safe from event loop)
if (ch.trySend(42) == ChannelStatus.OK) {
writeln("Sent!");
}
// Non-blocking receive (safe from event loop)
int value;
if (ch.tryReceive(value) == ChannelStatus.OK) {
writeln("Received: ", value);
}Example (blocking, worker thread only):
// Only use from worker threads, never from event loop!
ch.blockingSend(42); // Blocks until space available
int value;
ch.blockingReceive(value); // Blocks until value availableT[] buffersize_t headsize_t tailsize_t countsize_t capacity_bool closed_Mutex mutexCondition notEmptyCondition notFullChannelStatus blockingSend(T value) @trustedSend a value into the channel, blocking if the channel is full.ChannelStatus blockingReceive(out T value) @trustedReceive a value from the channel, blocking if empty.ChannelStatus trySend(T value, CancelToken token) @trustedChannelStatus tryReceive(out T value, CancelToken token) @trustedChannelStatus blockingSend(T value, CancelToken token) @trustedChannelStatus blockingReceive(out T value, CancelToken token) @trusted