Package groovy.concurrent

# Class ChannelSelect.Offer

java.lang.Object
groovy.concurrent.ChannelSelect.Offer

Enclosing class:
  ChannelSelect

public static final class ChannelSelect.Offer extends Object
One branch of a select: an input guard created by `ChannelSelect.receive(AsyncChannel)`, an output guard created by `ChannelSelect.send(AsyncChannel, Object)`, or a timeout created by `ChannelSelect.after(long)`. Immutable and freely reusable across selects.

Since:
  6.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `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(boolean...)`.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### when

    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(boolean...)`.

         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 `ChannelSelect.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(boolean...)` 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