Class CoroutineStep<I,​O>

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected CoroutineStep()
      Creates a new instance.
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract O execute​(I input, Continuation<?> continuation)
      This method must be implemented by subclasses to provide the actual functionality of this step.
      void runAsync​(java.util.concurrent.CompletableFuture<I> previousExecution, CoroutineStep<O,​?> nextStep, Continuation<?> continuation)
      Runs this execution step asynchronously as a continuation of a previous code execution in a CompletableFuture and proceeds to the next step afterwards.
      O runBlocking​(I input, Continuation<?> continuation)
      Runs this execution immediately, blocking the current thread until the execution finishes.
      protected void terminateCoroutine​(Continuation<?> continuation)
      Allow subclasses to terminate the coroutine they currently run in.
      java.lang.String toString()
      • Methods inherited from class org.obrel.core.RelatedObject

        deleteRelation, get, getRelation, getRelations, notifyRelationListeners, readRelations, relationsEqual, relationsHashCode, relationsString, set, set, transform, writeRelations
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface de.esoco.lib.property.Fluent

        _with
      • Methods inherited from interface org.obrel.core.FluentRelatable

        with, with, with
      • Methods inherited from interface org.obrel.core.Relatable

        deleteRelation, deleteRelation, deleteRelations, get, getAll, getOption, getRelation, getRelationCount, getRelations, getRelations, hasFlag, hasRelation, hasRelations, init, set, set, set, set, set, setOption, streamRelations, transform
    • Constructor Detail

      • CoroutineStep

        protected CoroutineStep()
        Creates a new instance.
    • Method Detail

      • runAsync

        public void runAsync​(java.util.concurrent.CompletableFuture<I> previousExecution,
                             CoroutineStep<O,​?> nextStep,
                             Continuation<?> continuation)
        Runs this execution step asynchronously as a continuation of a previous code execution in a 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).

        Parameters:
        previousExecution - The future of the previous code execution
        nextStep - The next step to execute or NULL for none
        continuation - The continuation of the execution
      • runBlocking

        public O runBlocking​(I input,
                             Continuation<?> continuation)
        Runs this execution immediately, blocking the current thread until the execution finishes.
        Parameters:
        input - The input value
        continuation - The continuation of the execution
        Returns:
        The execution result
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class org.obrel.core.RelatedObject
      • execute

        protected abstract O execute​(I input,
                                     Continuation<?> continuation)
        This method must be implemented by subclasses to provide the actual functionality of this step.
        Parameters:
        input - The input value
        continuation - The continuation of the execution
        Returns:
        The result of the execution
      • terminateCoroutine

        protected void terminateCoroutine​(Continuation<?> continuation)
        Allow subclasses to terminate the coroutine they currently run in.
        Parameters:
        continuation - The continuation of the current execution