pecan.ICo<...>
pecan.ICo<TIn, TOut, TRet>
is the interface of a coroutine.
The type parameter TIn
represents values that the coroutine can accept()
, TOut
represents values that the coroutine can yield(...)
, and TRet
represents the return value.
public var state(get, never):pecan.CoState
Current state of the coroutine. See states.
public var returned(get, never):Null<TRet>
Value returned by the coroutine, if available. null
otherwise.
public var onHalt:()->Void
Callback invoked when the coroutine terminates in any manner. This field should never be set to null
.
Note that adding a callback after a coroutine has finished has no effect. This may be important for coroutines that do not suspend at all between their invocation and their termination. The callback can be set after a runSuspended(...)
call to avoid this problem.
public function tick():Void
Moves the coroutine forward until a suspend point is hit, but only if it was in a Ready
state to begin with. Does nothing otherwise.
public function suspend():Void
Suspends the coroutine, stopping its execution, and changes its state to Suspended
.
public function wakeup():Void
Wakes up and tick
s a coroutine from a Ready
or Suspended
state.
public function terminate():Void
Terminates the coroutine, stopping its execution, and changes its state to Terminated
. A terminated coroutine may not be woken up again.
public function give(value:TIn):Void
Gives a value to a coroutine in an Accepting
state. This should be called when a coroutine expects a value from an accept()
call. The coroutine is tick
ed beforehand.
public function take():TOut
Takes a value from a coroutine in a Yielding
state. This should be called when a coroutine is providing a value using a yield(...)
call. The coroutine is tick
ed beforehand.
public function goto(label:String):Void
Goes to a label defined in the coroutine with a label("...")
point, then tick
. Throws an exception if the label does not exist.