public class Coroutines
extends java.lang.Object
Coroutine
management functions and relation types. If
not stated otherwise the configuration relation types can be set on any level
from coroutine to context.Modifier and Type | Field and 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.
|
Modifier and Type | Method and Description |
---|---|
static void |
closeManagedResources(org.obrel.core.Relatable rState,
java.util.function.Consumer<java.lang.Throwable> fErrorHandler)
Iterates over all relations in the given state object that are annotated
with
MetaTypes.MANAGED and closes them if they implement the
AutoCloseable interface. |
static CoroutineContext |
getDefaultContext()
Returns the default
CoroutineContext . |
static void |
setDefaultContext(CoroutineContext rContext)
Sets the default
CoroutineContext . |
public static final org.obrel.core.RelationType<java.util.function.Consumer<java.lang.Throwable>> EXCEPTION_HANDLER
public static final org.obrel.core.RelationType<de.esoco.lib.event.EventDispatcher<CoroutineEvent>> COROUTINE_LISTENERS
public static final org.obrel.core.RelationType<java.util.function.BiConsumer<Suspension<?>,java.lang.Boolean>> COROUTINE_SUSPENSION_LISTENER
public static final org.obrel.core.RelationType<java.util.function.BiConsumer<CoroutineStep<?,?>,Continuation<?>>> COROUTINE_STEP_LISTENER
public static void closeManagedResources(org.obrel.core.Relatable rState, java.util.function.Consumer<java.lang.Throwable> fErrorHandler)
MetaTypes.MANAGED
and closes them if they implement the
AutoCloseable
interface. This is invoked automaticallyrState
- The state relatable to check for managed resourcesfErrorHandler
- A consumer for exceptions that occur when closing a
resourcepublic static CoroutineContext getDefaultContext()
CoroutineContext
.public static void setDefaultContext(CoroutineContext rContext)
CoroutineContext
. The context will be used for
all coroutines that are started without an explicit context.rContext
- The new default context or NULL for none