`require-await` should be disabled for async generators
See original GitHub issueWhat rule do you want to change? require-await
Does this change cause the rule to produce more or fewer warnings? neither
How will the change be implemented? (New option, new default behavior, etc.)? new default behavior
Please provide some example code that this change will affect:
Currently, require-await
is enabled for both async functions and async generators.
The problem with this when it comes to generators is that the return value of an async generator contains symbols that a regular generator does not, making it quite different from async functions which are just regular functions that return promises.
Since generators yield rather than return a value, an async generator might yield all the values of another async generator without ever actually needing to use await.
async function * () {
yield * anotherAsyncGenerator()
}
If you remove the async syntax the generator will fail with the following error:
TypeError: yield* (intermediate value) is not iterable
You can’t actually yield * of an async generator from a regular generator because the generator has to have the right symbols in order to be consumed properly. The VM guards against this and gives us a rather obtuse error.
IMO, it’s probably best to just disable await checking for async generators.
What does the rule currently do for this code? It fails on the required form and will not pass unless disabled.
What will the rule do after it’s changed? Not check async generators for await.
Are you willing to submit a pull request to implement this change? Nope.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:10 (5 by maintainers)
Top GitHub Comments
I’ll pick it up
@ljharb oh totally, i wouldn’t even know how to do that if i hadn’t had to dig through Node.js Core’s async generator support for Streams. most JS developers don’t even know
Symbol
is a thing 😉