haxetink / tink_core

Core utilities
https://haxetink.github.io/tink_core
MIT License
117 stars 33 forks source link

Future is not suspended when removing the last/only callback link #131

Closed nadako closed 4 years ago

nadako commented 4 years ago

This will unsubscribe from the Future, but won't suspend it :(

import tink.core.Future;

function main() {
    var future = new Future(yield -> {
        trace("start");
        var timer = haxe.Timer.delay(() -> yield("done"), 1000);
        () -> { trace("stop"); timer.stop(); }
    });

    var link = future.handle(s -> trace(s));

    // haxe.Timer.delay(link.cancel, 500);
    link.cancel();
}

Quick debugging suggests that it's the CallbackList.release method doesn't check if the list is drained unless it's time to compact. Am I doing wrong assumption about when the future is suspended or is this a bug?

nadako commented 4 years ago

Nice, thank you! Now I'm safe to present this example to my team ^^