Optional
signal: AbortSignalOptionally provide AbortSignal to cancel the call. Once
the signal is aborted, select()
will throw AbortedError
and cancel all reads
Tuple of [channel, value]
- the selected channel and the value
read from it. value
is undefined
if the channel has closed
Like
select {}
statement in Go, oralts!
statement from Clojure'score.async
. Currently supports only reading, not writingAllows to read from multiple channels at once, whichever has a value or closes first. This is similar to
Promise.race(channels.map(c => c.read()))
, except:Only the selected channel will be read from. Values of other channels will remain intact (
Promise.race
example would read from all channels and discard other values)select()
tries to be fair: if multiple channels have a value, one is selected at random (Promise.race
would always select the one earlier in the array). This is similar to behavior of Go'sselect {}