Reflection to know if executed within a generator/async ?
a.d.bergi at web.de
Mon Dec 7 00:48:22 UTC 2015
Andrea Giammarchi schrieb:
> simply adding
> async and await and the only change to do in a well known/used
> *synchronous* API would be to check if the returned value is held and
> behave accordingly?
No, making a consumer of an API asynchronous should not be simple.
Unless you are only writing pure functions, everything that involves
states will very likely break. Concurrency is not trivial, it needs a
lot of consideration.
> as soon as you go for
> async/await or a generator that function will return a Promise for you.
Please never do that. Functions that sometimes return promises and
sometimes not are already known to be an antipattern. Making this
obscurely dependent on some fragile syntactic conditions could only make
If you want to migrate your library to asynchrony, just make it a
breaking change. Your consumers will thank you for it.
More information about the es-discuss