Package de.esoco.coroutine
Class Coroutines
- java.lang.Object
-
- de.esoco.coroutine.Coroutines
-
public class Coroutines extends java.lang.ObjectContains globalCoroutinemanagement 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_LISTENERSConfiguration: 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_LISTENERConfiguration: a single listener for coroutine step executions.static org.obrel.core.RelationType<java.util.function.BiConsumer<Suspension<?>,java.lang.Boolean>>COROUTINE_SUSPENSION_LISTENERConfiguration: a single listener for coroutine suspensions.static org.obrel.core.RelationType<java.util.function.Consumer<java.lang.Throwable>>EXCEPTION_HANDLERConfiguration: A handler for coroutine exceptions.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseManagedResources(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 withMetaTypes.MANAGEDand closes them if they implement theAutoCloseableinterface.static CoroutineContextgetDefaultContext()Returns the defaultCoroutineContext.static voidsetDefaultContext(CoroutineContext context)Sets the defaultCoroutineContext.
-
-
-
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 withMetaTypes.MANAGEDand closes them if they implement theAutoCloseableinterface. This is invoked automatically- Parameters:
state- The state relatable to check for managed resourceserrorHandler- A consumer for exceptions that occur when closing a resource
-
getDefaultContext
public static CoroutineContext getDefaultContext()
Returns the defaultCoroutineContext.- Returns:
- The default context
-
setDefaultContext
public static void setDefaultContext(CoroutineContext context)
Sets the defaultCoroutineContext. 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
-
-