Generators are functions that, in essence, are paused and returned to their callers. But when called, they must synchronously return a value or complete. Therefore, they cannot return the result of an asynchronous operation for the same reason that ordinary functions cannot return the result of an asynchronous operation.
As Benjamin noted, there is an ES7 proposal for asynchronous generators that would allow them to do this, but this is ES7 and is already noticeable in the future at this stage. The syntax of consumption is also affected (it is clear, it is important that people writing a call know that something is happening in async, we canβt have ordinary functions look synchronous when they are not).
According to the current sentence, your code using asynchronous function generators will look something like this:
for (var user on users()) { console.log(user); }
(Note on on instead of in or of .) But that can change.
source share