Package de.esoco.coroutine
Class Selection<T,V,R>
- java.lang.Object
-
- de.esoco.coroutine.Suspension<T>
-
- de.esoco.coroutine.Selection<T,V,R>
-
public class Selection<T,V,R> extends Suspension<T>
ASuspensionsubclass that selects the suspension result from one or more of multiple continuations based on certain criteria. If a child continuation fails the selection step will also fail. If a child continuation is cancelled, it will simply be ignored.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Continuation<? extends V> continuation)Adds a continuation to this group.voidcancel()Cancels this suspension.static <T,V>
Selection<T,V,java.util.Collection<V>>ofMultipleValues(CoroutineStep<?,T> suspendingStep, CoroutineStep<java.util.Collection<V>,?> resumeStep, Continuation<?> rContinuation, java.util.function.Predicate<Continuation<?>> checkComplete, java.util.function.Predicate<Continuation<?>> checkSelect)Creates a new instance for the selection of multiple values.static <T> Selection<T,T,T>ofSingleValue(CoroutineStep<?,T> suspendingStep, CoroutineStep<T,?> resumeStep, Continuation<?> continuation, java.util.function.Predicate<Continuation<?>> checkSelect)Creates a new instance for the selection of a single value.voidseal()Seals this instance so that no more coroutines can be added withadd(Continuation).java.lang.StringtoString()-
Methods inherited from class de.esoco.coroutine.Suspension
continuation, fail, ifNotCancelled, isCancelled, onCancel, resume, resume, suspendingStep, value, withValue
-
-
-
-
Method Detail
-
ofMultipleValues
public static <T,V> Selection<T,V,java.util.Collection<V>> ofMultipleValues(CoroutineStep<?,T> suspendingStep, CoroutineStep<java.util.Collection<V>,?> resumeStep, Continuation<?> rContinuation, java.util.function.Predicate<Continuation<?>> checkComplete, java.util.function.Predicate<Continuation<?>> checkSelect)
Creates a new instance for the selection of multiple values. If no values are selected the result will be an empty collection.- Parameters:
suspendingStep- The step that initiated the suspensionresumeStep- The step to resume the execution withrContinuation- The continuation of the executioncheckComplete- The condition for the termination of the selectioncheckSelect- The condition for the selection of results- Returns:
- The new instance
-
ofSingleValue
public static <T> Selection<T,T,T> ofSingleValue(CoroutineStep<?,T> suspendingStep, CoroutineStep<T,?> resumeStep, Continuation<?> continuation, java.util.function.Predicate<Continuation<?>> checkSelect)
Creates a new instance for the selection of a single value. If no value is selected the result will be NULL.- Parameters:
suspendingStep- The step that initiated the suspensionresumeStep- The step to resume the execution withcontinuation- The continuation of the executioncheckSelect- The condition for the selection of results- Returns:
- The new instance
-
add
public void add(Continuation<? extends V> continuation)
Adds a continuation to this group.- Parameters:
continuation- The continuation
-
cancel
public void cancel()
Description copied from class:SuspensionCancels this suspension. This willcancelthe continuation. Tries to resume a cancelled suspension will be ignored. If a cancel handler has been registered withSuspension.onCancel(Option)it will be invoked.- Overrides:
cancelin classSuspension<T>
-
seal
public void seal()
Seals this instance so that no more coroutines can be added withadd(Continuation). Sealing is necessary to allow the adding of further coroutines even if previously added coroutines have already finished execution.
-
toString
public java.lang.String toString()
Description copied from class:Suspension- Overrides:
toStringin classSuspension<T>
-
-