public class Collect<I,O> extends CoroutineStep<I,java.util.Collection<O>>
when(Predicate)
. Also by
default all coroutines will be awaited before resuming but that can be
controlled with until(Predicate)
. If the collecting is finished all
coroutines that are still running will be cancelled.
To select exactly only one result from multiple coroutines the related
step implementation Select
can be used.
Constructor and Description |
---|
Collect(java.util.Collection<Coroutine<? super I,? extends O>> rFromCoroutines)
Creates a new instance.
|
Modifier and Type | Method and Description |
---|---|
Collect<I,O> |
and(Coroutine<? super I,? extends O> rCoroutine)
Creates a new instance that collects the result of an additional
coroutine.
|
Collect<I,O> |
and(CoroutineStep<? super I,? extends O> rStep)
Creates a new instance that collects the result of an additional step.
|
static <I,O> Collect<I,O> |
collect(Coroutine<? super I,? extends O>... rFromCoroutines)
Suspends the coroutine execution until all coroutines finish and then
resumes the execution with a collection of the results.
|
static <I,O> Collect<I,O> |
collect(CoroutineStep<? super I,? extends O>... rFromSteps)
Suspends the coroutine execution until one coroutine step finishes.
|
protected java.util.Collection<O> |
execute(I rInput,
Continuation<?> rContinuation)
This method must be implemented by subclasses to provide the actual
functionality of this step.
|
void |
runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution,
CoroutineStep<java.util.Collection<O>,?> rNextStep,
Continuation<?> rContinuation)
Runs this execution step asynchronously as a continuation of a previous
code execution in a
CompletableFuture and proceeds to the next
step afterwards. |
Collect<I,O> |
until(java.util.function.Predicate<Continuation<?>> pCompletionCriteria)
Adds a condition for the termination of the result collection.
|
Collect<I,O> |
when(java.util.function.Predicate<Continuation<?>> pCollectCriteria)
Adds a condition for the result collection.
|
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
@SafeVarargs public static <I,O> Collect<I,O> collect(Coroutine<? super I,? extends O>... rFromCoroutines)
until(Predicate)
which will return a new Collect
instance. Modified instances that
select from additional coroutines or steps can be created with and(Coroutine)
and and(CoroutineStep)
.rFromCoroutines
- The coroutines to select from@SafeVarargs public static <I,O> Collect<I,O> collect(CoroutineStep<? super I,? extends O>... rFromSteps)
collect(Coroutine...)
.rFromSteps
- The coroutine steps to select frompublic Collect<I,O> and(Coroutine<? super I,? extends O> rCoroutine)
rCoroutine
- The additional coroutine to select frompublic Collect<I,O> and(CoroutineStep<? super I,? extends O> rStep)
and(Coroutine)
.rStep
- The additional step to select frompublic void runAsync(java.util.concurrent.CompletableFuture<I> fPreviousExecution, CoroutineStep<java.util.Collection<O>,?> rNextStep, Continuation<?> rContinuation)
CompletableFuture
and 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 Suspension.resume(Object)
.
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 Continuation.fail(Throwable)
.
runAsync
in class CoroutineStep<I,java.util.Collection<O>>
fPreviousExecution
- The future of the previous code executionrNextStep
- The next step to execute or NULL for nonerContinuation
- The continuation of the executionpublic Collect<I,O> until(java.util.function.Predicate<Continuation<?>> pCompletionCriteria)
Any collection criteria provided through when(Predicate)
are
not automatically applied to the completion criteria and must therefore
be handled explicitly in the completion test if necessary.
pCompletionCriteria
- A condition that checks if a result should be
selectedpublic Collect<I,O> when(java.util.function.Predicate<Continuation<?>> pCollectCriteria)
pCollectCriteria
- A condition that checks if a result should be
collectedprotected java.util.Collection<O> execute(I rInput, Continuation<?> rContinuation)
execute
in class CoroutineStep<I,java.util.Collection<O>>
rInput
- The input valuerContinuation
- The continuation of the execution