Yes, I was working on a proposal 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!
I’m using 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.
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):
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.