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.
| 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. |
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.
condition - the guard, consulted once per select