- Notifications
You must be signed in to change notification settings - Fork 26.8k
Description
I guess no-return-await rule should be disabled according to the following issue:
eslint/eslint#11878
Here is some resources:
Long story short:
Here is the example slightly changed to have "return await". Try function "foo" with or without "await" in a current version of Chrome (node.js v12.4 worked too when I just tried).
Without the "await" foo() does not appear in the stack trace, if it waits for bar() to finish it does appear. That asynchronous stack trace comes at "zero cost" and is enabled by default in current V8.
(function () { async function foo() { // return bar(); return await bar(); } async function bar() { await Promise.resolve(); throw new Error('BEEP BEEP'); } foo().catch(error => console.log(error.stack)); })()Without "await" in foo():
Error: BEEP BEEP at bar (<anonymous>:8:11)Error: BEEP BEEP at bar (<anonymous>:8:11) at async foo (<anonymous>:3:12)Yes return await promise; is useless on the "happy path". But when there is a rejection...
Of course there is a slight RAM cost, the context of the calling function now has to be kept around longer. Unless there is lots of looping or recursion going on that should not be relevant I'd say, compared to getting the stack trace when things go wrong in a lower-level promise creating async function.