Import std.concurrent.channels
std.concurrent.channels
A Channel's waits that a Cancellation stops, and Selector, which waits on several Channels at once, and a timeout. Each looks with TryReceive or TrySend and, finding nothing, waits for the job pool's generation to change, which every Channel's change, every job's end, and every Cancel moves on, so it looks again only once something could have changed.
std/concurrent/channels.fb
Types
Selector
class
Public Class Selector
Waits on several Channels at once: Wait takes a value from the first of them, in the order On gave them, that has one, and gives it to that Channel's handler, or runs the timeout's handler once its time passes with none. It's a builder: Selector().On(orders, Take).On(quit, Stop).Timeout(1.Seconds, Idle).Wait(). What it waits for blocks its thread, as a Channel's Receive does.
std/concurrent/channels.fb, line 58
-
A new Selector, with no cases and no timeout.
-
Waits on
channeltoo, whose values go tohandler. -
Runs
handlerwhen time passes in a Wait with no value. A Selector has one timeout, which this replaces. -
Waits until a Channel has a value, which goes to its handler, or the timeout passes, which runs its handler, and gives True; or until every Channel is closed and empty, as none will have a value, and gives False.
-
Waits as Wait does, unless the cancellation is cancelled first, or is already, which throws a CancelledError and takes no value.
Functions
Receive
function
Public Function Receive<T: Sendable>(channel: Channel<T>, cancel: Cancellation): T? Throws CancelledError
Receives channel's oldest value, waiting while it has none, unless the cancellation is
cancelled first, or is already, which throws a CancelledError and takes none. Null once the
Channel is closed and empty, as its Receive gives.
Send
function
@PanicsAtCaller Public Function Send<T: Sendable>(channel: Channel<T>, value: T, cancel: Cancellation) Throws CancelledError
Sends value on channel, waiting while it's full, unless the cancellation is cancelled first,
or is already, which throws a CancelledError and sends nothing. Panics once the Channel is
closed, as its Send does.
Report an issue with this page or with FutureBlitz on GitHub.