haxetink / tink_await

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

@async short lambdas not unpacked correctly? #38

Open cambiata opened 4 years ago

cambiata commented 4 years ago

Using tink_await 0.6.0, oldschool anonymous functions work as expected, but arrowfunctions don't - the return value isn't unpacked correctly. Noticed when trying Future.ofJsPromise as below, but the same seems to happen when using all Futures:

@await class Main {
    @async static function main() { 

        // This works fine:
        js.Browser.document.onmousedown = @async function(e) {
            var int = @await Future.ofJsPromise(testJsPromise());
            trace(int); // traces 1234
        };

        // This doesn't:
        js.Browser.document.onmousedown = @async (e)-> {
            var int = @await Future.ofJsPromise(testJsPromise());
            trace(int); // traces the promise method    
        };
    }

    static function testJsPromise():Promise<Int> {
        return new Promise<Int>((res, rej)->{
            haxe.Timer.delay(()->res(1234), 1000);
        });
    }
}