Reflection to know if executed within a generator/async ?

Claude Pache claude.pache at gmail.com
Sat Dec 5 08:20:34 UTC 2015


> Le 4 déc. 2015 à 18:31, Andrea Giammarchi <andrea.giammarchi at gmail.com> a écrit :
> 
> 
> async works with old code, old code cannot be promoted to async one. All I am trying to explain is that I'd love to give well known, de-facto standard, universally used APIs the ability to behave, for real, asynchronously whenever the future of the language is available.
> 
> How bad is that?
> 
> Regards
> 

I think that the only place where you can safely provide a promise when a value was previously expected, is when you are in tail-position inside an async function (as part of either `await` or `return`). The "tail-position" restriction is bad for your case, because it is easy to switch between tail- and non-tail-position by refactoring, and thus switching semantics unexpectedly.

Given that sync and async code may behave differently (race conditions...), picking randomly (because of unreliable guess) one semantics or the other is going to make it more difficult to debug.

—Claude



More information about the es-discuss mailing list