Package: groovy.concurrent

## [Java] Class ChannelSelect.Offer

- groovy.concurrent.ChannelSelect.Offer

-     public static final class ChannelSelect.Offer
      extends Object

  One branch of a select: an input guard created by receive(AsyncChannel), an output guard created by send(AsyncChannel, Object), or a timeout created by after(long). Immutable and freely reusable across selects.

  Since:
    6.0.0

- - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public ChannelSelect.Offer` | `when(BooleanSupplier condition)` Returns a copy of this offer guarded by `condition`: the precondition written onto the branch itself, as occam, Ada, Erlang and Kotlin write it, rather than passed positionally to ChannelSelect.select.

  - ### Inherited Methods Summary

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

- - ### Method Detail

    - #### public ChannelSelect.Offer when(BooleanSupplier condition)

      Returns a copy of this offer guarded by `condition`: the precondition written onto the branch itself, as occam, Ada, Erlang and Kotlin write it, rather than passed positionally to ChannelSelect.select.

          def sel = offers(receive(input).when { size < capacity },
                            receive(request).when { size > 0 })
           def result = await sel.select()

      The condition is evaluated afresh on every ChannelSelect.select call — that is why it is a supplier and not a boolean — so one guarded select may be held and reused as the state it guards on changes. When it does not hold, the offer is not registered on its channel: nothing is taken from it and nothing is sent to it, and the remaining offers keep their positions, so Result.getIndex denotes the same branch either way.

      Guards conjoin: over a second `when` both conditions must hold, as must the corresponding flag of a ChannelSelect.select call. If no offer of a select is enabled the result fails with IllegalStateException, since there is nothing left to wait for.

      Parameters:
        `condition` - the guard, consulted once per select
      Returns:
        a guarded copy of this offer
      Since:
        6.0.0