How to use await with mysql request?

how to use await with mysql request?

I found tink_await lib ,but there are few detail about how to use .

package;



import haxe.MainLoop;
import Random;
using tink.CoreApi;



 
@await class Main {
	@await static function main() {
		trace("start");
		@await foo();//it's still block mainThread.what async ?
		trace(2);
	}
	
	@async static function foo() {
		
		
		
		var i = 0;
		while (i < 1000000){
			Random.string(12);
		}
		
		return 0;
		
	}
	
	static function check() {
		$type(main); // Void -> Void
		$type(foo); // Void -> tink.core.Promise<Int>
	}
}

I did a test ,can’t see what’s async …it’s still block mainthread

This is doing exactly what it should, @await means: wait/block here until this async function is finished.

You probably want to just directly call foo and use its promise return Tinkerbell Core.

“Good ol’ JavaScript-style callbacks” are often still the best way to approach such things. Throw the request and arrange for a function to be called when it completes. Don’t wait around for it.

I thought people had seen that a “callback hell” wasn’t the best approach and invented promises. But they turned out to be not enough elegant too and finally people came up with async/await syntax sugar;)