Class Coroutines


  • public class Coroutines
    extends java.lang.Object
    Contains global Coroutine management functions and relation types. If not stated otherwise the configuration relation types can be set on any level from coroutine to context.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.obrel.core.RelationType<de.esoco.lib.event.EventDispatcher<CoroutineEvent>> COROUTINE_LISTENERS
      Configuration: coroutine event listeners that will be invoked when coroutines are started or finished.
      static org.obrel.core.RelationType<java.util.function.BiConsumer<CoroutineStep<?,​?>,​Continuation<?>>> COROUTINE_STEP_LISTENER
      Configuration: a single listener for coroutine step executions.
      static org.obrel.core.RelationType<java.util.function.BiConsumer<Suspension<?>,​java.lang.Boolean>> COROUTINE_SUSPENSION_LISTENER
      Configuration: a single listener for coroutine suspensions.
      static org.obrel.core.RelationType<java.util.function.Consumer<java.lang.Throwable>> EXCEPTION_HANDLER
      Configuration: A handler for coroutine exceptions.
    • Field Detail

      • EXCEPTION_HANDLER

        public static final org.obrel.core.RelationType<java.util.function.Consumer<java.lang.Throwable>> EXCEPTION_HANDLER
        Configuration: A handler for coroutine exceptions. The main purpose of this is to process exception stacktraces when they occur. All coroutine exceptions will also be available from the finished scope.The default value prints the stacktrace of a failed coroutine execution to the console.
      • COROUTINE_LISTENERS

        public static final org.obrel.core.RelationType<de.esoco.lib.event.EventDispatcher<CoroutineEvent>> COROUTINE_LISTENERS
        Configuration: coroutine event listeners that will be invoked when coroutines are started or finished.
      • COROUTINE_SUSPENSION_LISTENER

        public static final org.obrel.core.RelationType<java.util.function.BiConsumer<Suspension<?>,​java.lang.Boolean>> COROUTINE_SUSPENSION_LISTENER
        Configuration: a single listener for coroutine suspensions. This listener will be invoked with the suspension and a boolean value after a coroutine has been suspended (TRUE) or before it is resumed (FALSE). This relation is intended mainly for debugging purposes.
      • COROUTINE_STEP_LISTENER

        public static final org.obrel.core.RelationType<java.util.function.BiConsumer<CoroutineStep<?,​?>,​Continuation<?>>> COROUTINE_STEP_LISTENER
        Configuration: a single listener for coroutine step executions. This listener will be invoked with the step and continuation just before a step is executed. This relation is intended mainly for debugging purposes.
    • Method Detail

      • closeManagedResources

        public static void closeManagedResources​(org.obrel.core.Relatable state,
                                                 java.util.function.Consumer<java.lang.Throwable> errorHandler)
        Iterates over all relations in the given state object that are annotated with MetaTypes.MANAGED and closes them if they implement the AutoCloseable interface. This is invoked automatically
        Parameters:
        state - The state relatable to check for managed resources
        errorHandler - A consumer for exceptions that occur when closing a resource
      • setDefaultContext

        public static void setDefaultContext​(CoroutineContext context)
        Sets the default CoroutineContext. The context will be used for all coroutines that are started without an explicit context.
        Parameters:
        context - The new default context or NULL for none