Add information to `no-return-await` docs about potential pitfalls.
See original GitHub issuereturn await
has subtly different semantics from just return
in async functions. Example:
async function failing() {
throw new Error('foo');
}
async function noAwait() {
try {
return failing();
} catch (e) {
return 'oops';
}
}
async function withAwait() {
try {
return await failing();
} catch (e) {
return 'oops';
}
}
noAwait().then(console.log, console.warn);
withAwait().then(console.log, console.warn);
This will call console.warn
with the ‘foo’ error, which is thrown from noAwait
. But it will log oops
from the withAwait
function. This is confusing behaviour, which might completely catch people off guard. So no, the await
after return
is not always superfluous, and recommending it’s removal might lead to subtle changes that was not expected.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:5
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Rules - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >JSHint Options Reference
Strict mode eliminates some JavaScript pitfalls that didn't cause errors by changing them to produce errors. It also fixes mistakes that made it...
Read more >Social Media Dangers Documentary — Childhood 2.0
FIND MORE RESOURCES AT: https://bit.ly/32voKpY For the first time in history, mental illness and suicide have become one of the greatest ...
Read more >In the Age of AI (full documentary) | FRONTLINE - YouTube
A documentary exploring how artificial intelligence is changing life as we know it — from jobs to privacy to a growing rivalry between...
Read more >Pyour core schedule - bpm kids
Please contact us for more information. Variety of classes for all types of clients. Surf City, NJ 8008. Full service Pilates & fitness...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sounds good to me!
@not-an-aardvark Any direction you want to provide in response to this comment? Or does the proposal there sound good? Thanks!