# Status of @await in Haxe

**URL:** https://community.haxe.org/t/status-of-await-in-haxe/566
**Category:** Haxe
**Tags:** async, nodejs
**Created:** [April 4, 2018, 4:27pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566 "2018-04-04T16:27:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![bubar](https://community.haxe.org/user_avatar/community.haxe.org/bubar/32/176_2.png) [@bubar](https://community.haxe.org/u/bubar)
#### Post date: [April 4, 2018, 4:27pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/1 "2018-04-04T16:27:44Z")

</div>

Hi there,

Does anyone have some infos about the usage of @await in Haxe ?

For instance, with nodejs target, is it possible to read a file , or perform a sequelize query in a synchronous style with @await ?

I’ve noticed the existence of [tink\_await (0.6.0)](https://lib.haxe.org/p/tink_await/) , but it’s limited to tink\_\* libs …

---

<div class="post-metadata">

### Author: ![RealyUniqueName](https://community.haxe.org/user_avatar/community.haxe.org/realyuniquename/32/10_2.png) [@RealyUniqueName](https://community.haxe.org/u/RealyUniqueName)
#### Post date: [April 5, 2018, 10:15am UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/2 "2018-04-05T10:15:23Z")

</div>

@nadako was trying to implement it. Maybe he can share some details.

---

<div class="post-metadata">

### Author: ![nadako](https://community.haxe.org/user_avatar/community.haxe.org/nadako/32/5_2.png) [@nadako](https://community.haxe.org/u/nadako)
#### Post date: [April 5, 2018, 8:37pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/3 "2018-04-05T20:37:24Z")

</div>

Yes, I was working on a [proposal](https://github.com/nadako/haxe-coroutines) for generic coroutines which can be used to implement `await` among other things and I still think this is a way to go, although error handling might be something to think about some more. I experimented with implementing the state machine transformation using the control flow graph that compiler is already building internally, but never finished a working prototype due to serious lack of time recently. Maybe it’ll be more realistic when HF gets a new full-time compiler developer, I’ll be happy to help!

---

<div class="post-metadata">

### Author: ![dmitryhryppa](https://community.haxe.org/user_avatar/community.haxe.org/dmitryhryppa/32/1815_2.png) [@dmitryhryppa](https://community.haxe.org/u/dmitryhryppa)
#### Post date: [April 6, 2018, 12:06pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/4 "2018-04-06T12:06:59Z")

</div>

I’m using a little bit tricky workaround for NodeJS, which can be replaced with macros via _@async_ and _@await_ metas I think:

> **[Try Haxe !](https://try.haxe.org/#6f2C9)**

---

<div class="post-metadata">

### Author: ![jcward](https://community.haxe.org/user_avatar/community.haxe.org/jcward/32/115_2.png) [@jcward](https://community.haxe.org/u/jcward)
#### Post date: [April 9, 2018, 6:23pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/5 "2018-04-09T18:23:50Z")

</div>

I’m using [haxe-continuation](https://github.com/Atry/haxe-continuation) – which I’ve found to work really well. It’s a single-purpose macro (instead of the big tink library), and can automatically wrap e.g. extern JS functions which take a callback as their last parameter. Note that the license is [not MIT](https://github.com/Atry/haxe-continuation/issues/6).

I’m going to talk about using it in my upcoming Haxe Summit talk.

It’s a slick macro that actually breaks your “synchronously-written functions” into multiple functions and callbacks, while maintaining scoped variables. Basically it’s re-writing your synchronous code as a set of asynchronous functions. It also has the interesting side effect of being able to assign multiple variables (because a callback function – which this is translated into – can take multiple parameters):

 ![image](https://community.haxe.org/uploads/default/original/1X/992867ecfe810d930f67131e30714a03c412ea79.png)

It’s also awesome that Haxe macros enable this kind of power.

It’s not perfect, though. It doesn’t provide any error handling options (e.g. optionally insert try/catch), and there aren’t any comments. 🙂 But, it works for now.

---

<div class="post-metadata">

### Author: ![fullofcaffeine](https://community.haxe.org/user_avatar/community.haxe.org/fullofcaffeine/32/28_2.png) [@fullofcaffeine](https://community.haxe.org/u/fullofcaffeine)
#### Post date: [April 11, 2018, 3:56pm UTC](https://community.haxe.org/t/status-of-await-in-haxe/566/6 "2018-04-11T15:56:37Z")

</div>

> [@jcward](#):
>
> It’s a slick macro that actually breaks your “synchronously-written functions” into multiple functions and callbacks, while maintaining scoped variables. Basically it’s re-writing your synchronous code as a set of asynchronous functions. It also has the interesting side effect of being able to assign multiple variables (because a callback function – w

Hi Jeff,

So there’s no equivalent of JS’ `Promise.prototype.catch` approach?
