# How to use await with mysql request?

**URL:** <https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969>\
**Category:** Haxe\
**Created:** [August 16, 2019, 2:57am UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969 "2019-08-16T02:57:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [August 16, 2019, 2:57am UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969/1 "2019-08-16T02:57:36Z")

</div>

how to use await with mysql request?

I found tink\_await lib ,but there are few detail about how to use .

---

<div class="post-metadata">

**Author:** ![Zhan](https://community.haxe.org/user_avatar/community.haxe.org/zhan/32/468_2.png) [@Zhan](https://community.haxe.org/u/Zhan)\
**Post date:** [August 16, 2019, 3:24am UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969/2 "2019-08-16T03:24:27Z")

</div>

```
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

---

<div class="post-metadata">

**Author:** ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)\
**Post date:** [August 28, 2019, 9:16am UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969/3 "2019-08-28T09:16:52Z")

</div>

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](https://haxetink.github.io/tink_core/#/types/promise).

---

<div class="post-metadata">

**Author:** ![sundialservices](https://avatars.discourse-cdn.com/v2/letter/s/9e8a1a/32.png) [@sundialservices](https://community.haxe.org/u/sundialservices)\
**Post date:** [August 28, 2019, 5:45pm UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969/4 "2019-08-28T17:45:39Z")

</div>

“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.

---

<div class="post-metadata">

**Author:** ![alex\_dja](https://community.haxe.org/user_avatar/community.haxe.org/alex_dja/32/294_2.png) [@alex\_dja](https://community.haxe.org/u/alex_dja)\
**Post date:** [August 29, 2019, 5:35am UTC](https://community.haxe.org/t/how-to-use-await-with-mysql-request/1969/5 "2019-08-29T05:35:17Z")

</div>

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;)
