@azerum/ts-csp
    Preparing search index...

    Function select

    • Like select {} statement in Go, or alts! statement from Clojure's core.async. Currently supports only reading, not writing

      Allows 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's select {}

      Type Parameters

      Parameters

      • channels: TArgs
      • Optionalsignal: AbortSignal

        Optionally provide AbortSignal to cancel the call. Once the signal is aborted, select() will throw AbortedError and cancel all reads

      Returns Promise<InferSelectResult<TArgs>>

      Tuple of [channel, value] - the selected channel and the value read from it. value is undefined if the channel has closed

      Read from ch or timeout:

      const [winnerCh, value] = await select([ch, timeout(1000)])

      if (winnerCh !== ch) {
      // Timed out
      }

      Read from ch or throw when signal is aborted:

      const [_, value] = await select([ch], signal)