Closed andyli closed 5 years ago
Try
@await class Main {
@await static function main() {
if(@await foo() == 1) return;
trace(2);
}
@async static function foo() return 1;
static function check() {
$type(main); // Void -> Void
$type(foo); // Void -> tink.core.Promise<Int>
}
}
There is a difference for @async
and @await
when used to annotate a function.
@async
expects a return value and the function will be transformed into returning a Promise<T>
@await
doesn't expect a return value and its return type will be Void
And currently there is no check to enforce @async
actually returns something for all the possible branches. But that is https://github.com/haxetink/tink_await/issues/6.
Ah, I see. Is the @async
@await
difference documented somewhere?
oops, looks like no. But there is an open issue for that https://github.com/haxetink/tink_await/issues/16
I guess copying your comment above into the README would be good enough.
Done, a bit rough but should be fine for now.
Done !
use return null instead of return.
Tested with Haxe 3.4.7 and tink_await 0.4.0.
Compile:
Results in:
The error can be avoided by replacing
return;
withreturn null;
. I guess it makes sense for tink_await to do thereturn;
->return null;
transformation automatically.