Package: groovy.concurrent

## [Java] Class ChannelSelect

- groovy.concurrent.ChannelSelect

-     public final class ChannelSelect
      extends Object

  Selects the first available value from multiple AsyncChannels.

  This is the channel equivalent of Awaitable.any — while `Awaitable.any` races futures, `ChannelSelect` races channel receives. Each call to select() returns an Awaitable that completes with a Result indicating which channel produced the value and what it was.

      def prices = AsyncChannel.create(10)
       def alerts = AsyncChannel.create(10)

       def sel = ChannelSelect.from(prices, alerts)
       def result = await sel.select()
       println "Channel ${result.index}: ${result.value}"

  Inspired by GPars' `Select` and Go's `select` statement.

  Since:
    6.0.0

- - ### Nested Class Summary

    Nested classes
    Modifiers | Name | Description
    --- | --- | ---
    `static class` | `ChannelSelect.Result` | The result of a select() operation, indicating which channel produced the value.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public static ChannelSelect` | `from(AsyncChannel<?> channels)` Creates a select over the given channels.
    `` | `public Awaitable<Result>` | `select()` Waits for the first value available from any of the channels.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class Object` | `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### @SafeVarargs
      public static ChannelSelect from(AsyncChannel<?> channels)

      Creates a select over the given channels.

      Parameters:
        `channels` - the channels to select from
      Returns:
        a new ChannelSelect

    - #### public Awaitable<Result> select()

      Waits for the first value available from any of the channels.

      Returns an Awaitable that completes with a Result containing the channel index and the received value.

      Values consumed by non-winning channels are re-sent back to those channels to prevent message loss. This may reorder values within a channel but guarantees no values are silently dropped.

      Returns:
        an awaitable result indicating which channel produced the value