I was just reading this fantastic article «Generators» and it clearly highlights this function, which is a helper function for handling generator functions:
what the heck is the difference between the
await
keyword and theyield
keyword?
The await
keyword is only to be used in async function
s, while the yield
keyword is only to be used in generator function*
s. And those are obviously different as well - the one returns promises, the other returns generators.
Does
await
always turn something into a promise, whereasyield
makes no such guarantee?
Yes, await
will call Promise.resolve
on the awaited value.
yield
just yields the value outside of the generator.