Class CoroutineContext

  • All Implemented Interfaces:
    org.obrel.core.Relatable

    public class CoroutineContext
    extends CoroutineEnvironment
    The context for the execution of Coroutines.
    • Constructor Summary

      Constructors 
      Constructor Description
      CoroutineContext()
      Creates a new instance that uses the common thread pool as the executor.
      CoroutineContext​(java.util.concurrent.Executor executor)
      Creates a new instance with a specific coroutine executor.
      CoroutineContext​(java.util.concurrent.Executor executor, java.util.concurrent.ScheduledExecutorService scheduler)
      Creates a new instance with a specific coroutine executor and scheduler.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void awaitAllScopes()
      Blocks until the coroutines of all scopes in this context have finished execution.
      java.util.concurrent.Executor getExecutor()
      Returns the executor to be used for the execution of the steps of a Coroutine.
      java.util.concurrent.ScheduledExecutorService getScheduler()
      Returns the executor to be used for the execution of timed steps in a Coroutine.
      long getScopeCount()
      Returns the number of currently active scopes.
      • Methods inherited from class org.obrel.core.RelatedObject

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

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.obrel.core.Relatable

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

      • CoroutineContext

        public CoroutineContext()
        Creates a new instance that uses the common thread pool as the executor.
      • CoroutineContext

        public CoroutineContext​(java.util.concurrent.Executor executor)
        Creates a new instance with a specific coroutine executor. If the executor also implements the ScheduledExecutorService interface it will also be used for scheduling purposes.
        Parameters:
        executor - The coroutine executor
      • CoroutineContext

        public CoroutineContext​(java.util.concurrent.Executor executor,
                                java.util.concurrent.ScheduledExecutorService scheduler)
        Creates a new instance with a specific coroutine executor and scheduler. The latter will be used to execute timed coroutine steps.
        Parameters:
        executor - The coroutine executor
        scheduler - The scheduled executor service
    • Method Detail

      • awaitAllScopes

        public void awaitAllScopes()
        Blocks until the coroutines of all scopes in this context have finished execution. If no coroutines are running or all have finished execution already this method returns immediately.
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
        Returns the executor to be used for the execution of the steps of a Coroutine.
        Returns:
        The coroutine executor for this context
      • getScheduler

        public java.util.concurrent.ScheduledExecutorService getScheduler()
        Returns the executor to be used for the execution of timed steps in a Coroutine. If no scheduler has been set in the constructor or created before a new instance with a pool size of 1 will be created by invoking Executors.newScheduledThreadPool(int).
        Returns:
        The coroutine scheduler for this context
      • getScopeCount

        public long getScopeCount()
        Returns the number of currently active scopes. This will only be a momentary value as the execution of the coroutines in the scopes happens asynchronously and some coroutines may finish while querying this count.
        Returns:
        The number of running coroutines