Class Selection<T,​V,​R>


  • public class Selection<T,​V,​R>
    extends Suspension<T>
    A Suspension subclass 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 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 suspension
        resumeStep - The step to resume the execution with
        rContinuation - The continuation of the execution
        checkComplete - The condition for the termination of the selection
        checkSelect - 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 suspension
        resumeStep - The step to resume the execution with
        continuation - The continuation of the execution
        checkSelect - 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: Suspension
        Cancels this suspension. This will cancel the continuation. Tries to resume a cancelled suspension will be ignored. If a cancel handler has been registered with Suspension.onCancel(Option) it will be invoked.
        Overrides:
        cancel in class Suspension<T>
      • seal

        public void seal()
        Seals this instance so that no more coroutines can be added with add(Continuation). Sealing is necessary to allow the adding of further coroutines even if previously added coroutines have already finished execution.