Aurel300 / pecan

Macro-based coroutines for Haxe
https://aurel300.github.io/pecan/
43 stars 8 forks source link

state is not correctly switched when @:pecan.accept returns synchronously #16

Open nadako opened 3 years ago

nadako commented 3 years ago
@:pecan.accept function sync(?ret:pecan.Void->Void, ?co:pecan.ICo<Any, Any, Any>):pecan.Void {
    ret(Void);
    return null;
}

@:pecan.accept function async(?ret:pecan.Void->Void, ?co:pecan.ICo<Any, Any, Any>):pecan.Void {
    haxe.Timer.delay(() -> ret(Void), 10);
    return null;
}

function main() {
    pecan.Co.co({
        sync();
        trace("hallo");
        async();
    }).run();
}

Output:

src/Main.hx:14: hallo
src/Main.hx:14: hallo
nadako commented 3 years ago

When I was working on haxe coroutines prototype I figured that we should set the next state before doing the suspending call.