public class Select<I,O> extends CoroutineStep<I,O>
when(Predicate). If a result is selected all coroutines that are sill running will be cancelled and execution of the selecting coroutine is resumed.
The main purpose of this step is to non-blockingly select the first result from other suspending coroutines although it can be used with arbitrary coroutines and steps. It should be noted that if both suspending and non-suspending selection targets are used the non-suspending targets will almost always be selected. Even when using only suspending coroutines the selection will be slightly biased towards the first coroutine because the coroutines need to be launched sequentially, giving the first coroutine(s) a head start.
To select more than one result from the child coroutines the related step
Collect can be used.
|Constructor and Description|
Creates a new instance.
|Modifier and Type||Method and Description|
This method must be implemented by subclasses to provide the actual functionality of this step.
Creates a new instance that selects from an additional coroutine.
Creates a new instance that selects from an additional step.
Runs this execution step asynchronously as a continuation of a previous code execution in a
Suspends the coroutine execution until one coroutine finishes and then resumes the execution with the result.
Suspends the coroutine execution until one coroutine step finishes.
Adds a condition for the result selection.
fail, runBlocking, terminateCoroutine, toString
deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
deleteRelation, deleteRelation, deleteRelations, get, get, get, getAll, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, streamRelations, transform
@SafeVarargs public static <I,O> Select<I,O> select(Coroutine<? super I,? extends O>... rFromCoroutines)
when(Predicate)which will return a new
Selectinstance. Modified instances that select from additional coroutines or steps can be created with
rFromCoroutines- The coroutines to select from
@SafeVarargs public static <I,O> Select<I,O> select(CoroutineStep<? super I,? extends O>... rFromSteps)
rFromSteps- The coroutine steps to select from
rCoroutine- The additional coroutine to select from
rStep- The additional step to select from
public void runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution, CoroutineStep<O,?> rNextStep, Continuation<?> rContinuation)
CompletableFutureand proceeds to the next step afterwards.
Subclasses that need to suspend the invocation of the next step until
some condition is met (e.g. sending or receiving data has finished) need
to override this method and create a
Suspension by invoking
Continuation.suspend(CoroutineStep, CoroutineStep) on the next
step. If the condition that caused the suspension resolves the coroutine
execution can be resumed by calling
Subclasses that override this method also need to handle errors by
terminating any further execution (i.e. not resuming a suspension if such
exists) and forwarding the causing exception to
public Select<I,O> when(java.util.function.Predicate<Continuation<?>> pSelectCriteria)
pSelectCriteria- A condition that checks if a result should be selected
protected O execute(I rInput, Continuation<?> rContinuation)