haxetink / tink_await

Haxe async/await
MIT License
58 stars 15 forks source link

This library seems to no longer work in Haxe 4.3.4? #49

Closed sonygod closed 2 months ago

sonygod commented 2 months ago

using tink.CoreApi;

class Main {
    public static function main() {
        trace('Hello World');

        var main = new MainAsync();

        main.testAwait();
    }
}

@await
class MainAsync {
    public function new() {}

    @async
    public function testAwait() {
        trace('start');
        @await waitForIt();
        trace('end');
    }

    function waitForIt() {
        var f1 = new Future(cb -> {
            var timer = haxe.Timer.delay(function() {
                cb(1);
            }, 5000);
            function() {
                timer.stop();
            }
        });
        return f1;
    }
}

I just test this small code ,but not work? what's wrong?

build.hxml

-cp src

-main Main
--library tink_await
--js bin/main.js
-D dce=full
sonygod commented 2 months ago

oh,sorry ,here is work.

using tink.CoreApi;

class Main {
    public static function main() {
        trace('Hello World');

        var main = new MainAsync();

        main.testAwait().handle(function(v) {
            trace('All async operations completed. $v');

        });
    }
}

@await
class MainAsync {
    public function new() {}

    @async
    public function testAwait() {
        trace('start');
        @await waitForIt();
        trace('end');
    }

    function waitForIt() {
        var f1 = new Future<Int>(cb -> {
            var timer = haxe.Timer.delay(function() {
                cb(1);
            }, 5000);
            return function() {
                timer.stop(); // 
            };
        });
        return f1;
    }
}