Package com.offbynull.coroutines.user
Class CoroutineRunner
- java.lang.Object
-
- com.offbynull.coroutines.user.CoroutineRunner
-
- All Implemented Interfaces:
java.io.Serializable
public final class CoroutineRunner extends java.lang.Object implements java.io.Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private Continuation
continuation
private Coroutine
coroutine
private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description CoroutineRunner(Coroutine coroutine)
Constructs aCoroutineRunner
object.CoroutineRunner(Coroutine coroutine, Continuation continuation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
execute()
Starts/resumes execution of this coroutine.java.lang.Object
getContext()
Get the context.(package private) Continuation
getContinuation()
Coroutine
getCoroutine()
Get the coroutine assigned to this runner.void
setContext(java.lang.Object context)
Set the context.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
coroutine
private Coroutine coroutine
-
continuation
private Continuation continuation
-
-
Constructor Detail
-
CoroutineRunner
public CoroutineRunner(Coroutine coroutine)
Constructs aCoroutineRunner
object.- Parameters:
coroutine
- coroutine to run- Throws:
java.lang.NullPointerException
- if any argument isnull
-
CoroutineRunner
CoroutineRunner(Coroutine coroutine, Continuation continuation)
-
-
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 callsContinuation.suspend()
), this method will returntrue
. If the coroutine has finished executing, this method will returnfalse
.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 callexecute()
again)
-
getContext
public java.lang.Object getContext()
Get the context. Accessible via theContinuation
object that gets used by this coroutine.- Returns:
- context context
-
setContext
public void setContext(java.lang.Object context)
Set the context. Accessible via theContinuation
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
-
getContinuation
Continuation getContinuation()
-
-