Labels
Labels can be declared inside coroutine bodies with the label(...)
call. Labels identify positions in the coroutine code that can be jumped to with a goto(...)
call. Label names must be a constant string expression.
Example: label(...)
and goto(...)
usage
var weather = pecan.Co.co({
label("sunny");
while (true) yield("sunny!");
label("rainy");
while (true) yield("rainy!");
}, null, (_:String)).run();
trace(weather.take()); // output: sunny!
trace(weather.take()); // output: sunny!
weather.goto("rainy");
trace(weather.take()); // output: rainy!
weather.goto("sunny");
trace(weather.take()); // output: sunny!