New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
require-await
should be disabled for async generators
#12459
Comments
I'll pick it up |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening this since it seems to have slipped between the cracks. This makes sense to me, but I’d like to hear what the rest of the team has to say. |
Sorry for the lack of activity here. This makes sense to me. |
This makes sense to me too, but a regular |
@ljharb it’s a bit different. If you want to require For an async generator this isn’t the case because a regular generator that wasn’t created using the syntax won’t have the correct symbols. |
You can manually make a function that returns an object with |
@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 |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Reopening since there are open PRs for this issue. |
* Fix: require-await should ignore async generators (fixes #12459) * Chore: docs update and test update * Docs: fixed typo for generator to generators Co-Authored-By: Kai Cataldo <kai@kaicataldo.com> * Chore: added more tests for async generators Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
What 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.
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.
The text was updated successfully, but these errors were encountered: