Class CoroutineRunner

  • All Implemented Interfaces:
    java.io.Serializable

    public final class CoroutineRunner
    extends java.lang.Object
    implements java.io.Serializable
    Used to execute a Coroutine. All Coroutines must be executed through this class.
    See Also:
    Serialized Form
    • Constructor Detail

      • CoroutineRunner

        public CoroutineRunner​(Coroutine coroutine)
        Constructs a CoroutineRunner object.
        Parameters:
        coroutine - coroutine to run
        Throws:
        java.lang.NullPointerException - if any argument is null
    • Method Detail

      • execute

        public boolean execute()
        Starts/resumes execution of this coroutine. If the coroutine being executed reaches a suspension point (meaning that the method calls Continuation.suspend()), this method will return true. If the coroutine has finished executing, this method will return false.

        Calling this method again after the coroutine has finished executing will restart the coroutine.

        Returns:
        false if execution has completed (the method has return), true if execution was suspended.
        Throws:
        CoroutineException - an exception occurred during execution of this coroutine, the saved execution stack and object state may be out of sync at this point (meaning that unless you know what you're doing, you should not call execute() again)
      • getContext

        public java.lang.Object getContext()
        Get the context. Accessible via the Continuation object that gets used by this coroutine.
        Returns:
        context context
      • setContext

        public void setContext​(java.lang.Object context)
        Set the context. Accessible via the Continuation object that gets used by this coroutine.
        Parameters:
        context - context
      • getCoroutine

        public Coroutine getCoroutine()
        Get the coroutine assigned to this runner.
        Returns:
        coroutine assigned to this runner