Invoking
To invoke a declared coroutine, call run(...). The arguments of run correspond to the arguments declared in the coroutine. The run call returns an instance of the coroutine, which will be of type pecan.ICo<...>.
Example: run() call with no arguments
var noArgs = pecan.Co.co({
trace("no arguments...");
});
noArgs.run(); // output: no arguments...
noArgs.run(); // output: no arguments...
Example: run(...) call with arguments
withArgs = pecan.Co.co((a:String) -> {
trace('called with $a');
});
withArgs.run("x"); // output: called with x
withArgs.run("y"); // output: called with y
By default, run(...) will start and immediately tick() the coroutine. If instead the coroutine should be started in a suspended state, the runSuspended(...) method with the same signature can be used.
Example: runSuspended()
var factory = pecan.Co.co({ trace("2"); });
var instance = factory.runSuspended();
trace("1");
instance.tick();
trace("3");
// output: 1, 2, 3