Package groovy.concurrent
Class ChannelSelect.Offer
java.lang.Object
groovy.concurrent.ChannelSelect.Offer
- Enclosing class:
- ChannelSelect
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 TypeMethodDescriptionwhen(BooleanSupplier condition) Returns a copy of this offer guarded bycondition: the precondition written onto the branch itself, as occam, Ada, Erlang and Kotlin write it, rather than passed positionally toChannelSelect.select(boolean...).
-
Method Details
-
when
Returns a copy of this offer guarded bycondition: the precondition written onto the branch itself, as occam, Ada, Erlang and Kotlin write it, rather than passed positionally toChannelSelect.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, soChannelSelect.Result.getIndex()denotes the same branch either way.Guards conjoin: over a second
whenboth conditions must hold, as must the corresponding flag of aChannelSelect.select(boolean...)call. If no offer of a select is enabled the result fails withIllegalStateException, 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
-