import { select } from "https://deno.land/x/async_channels@1.0.0-alpha45/mod.ts";
select
takes a list of channel operations, and completes at-most one of
them (the first operation that is ready).
If the default
option is provided, and no operation is immediately read,
then all the operations will be aborted and the default value is returned.
Parameters
A list of channel operations. Each item in this list can be either a receiver or a tuple of a sender and the value to send.
The options for select
.
Note: undefined
is considered a valid value for default
, so if you
want to wait for one of the operations, omit default
from the options
struct.
Returns
If default is provided and no operation was ready, then the tuple
[default, undefined]
is returned.
If a receive
operation is completed, then the tuple [T, Receiver<T>]
is returned (where T
is the value received, and Receiver<T>
is the
receiver channel that returned it).
If a send
operation is completed, then the tuple [true, Sender<T>]
is
returned (where Sender<T>
is the sender channel that we sent the value
with).