Skip to content

Commit 82a448a

Browse files
LinusUKai Cataldo
andauthored
Docs: improve documentation of no-return-await (#13215)
* Docs: improve documentation of no-return-await * Docs: add try/catch caveat to no-return-await Co-Authored-By: Kai Cataldo <kai@kaicataldo.com> * Docs: fix typo in documentation of no-return-await Co-Authored-By: Kai Cataldo <kai@kaicataldo.com> * Docs: apply suggestions from code review Co-authored-by: Kai Cataldo <kai@kaicataldo.com> Co-authored-by: Kai Cataldo <kai@kaicataldo.com>
1 parent 742941d commit 82a448a

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

docs/rules/no-return-await.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Disallows unnecessary `return await` (no-return-await)
22

3-
Inside an `async function`, `return await` is seldom useful. Since the return value of an `async function` is always wrapped in `Promise.resolve`, `return await` doesn’t actually do anything except add extra time before the overarching Promise resolves or rejects. The only valid exception is if `return await` is used in a try/catch statement to catch errors from another Promise-based function.
3+
Using `return await` inside an `async function` keeps the current function in the call stack until the Promise that is being awaited has resolved, at the cost of an extra microtask before resolving the outer Promise. `return await` can also be used in a try/catch statement to catch errors from another function that returns a Promise.
4+
5+
You can avoid the extra microtask by not awaiting the return value, with the trade off of the function no longer being a part of the stack trace if an error is thrown asynchronously from the Promise being returned. This can make debugging more difficult.
46

57
## Rule Details
68

@@ -42,7 +44,11 @@ In the last example the `await` is necessary to be able to catch errors thrown f
4244

4345
## When Not To Use It
4446

45-
If you want to use `await` to denote a value that is a thenable, even when it is not necessary; or if you do not want the performance benefit of avoiding `return await`, you can turn off this rule.
47+
There are a few reasons you might want to turn this rule off:
48+
49+
- If you want to use `await` to denote a value that is a thenable
50+
- If you do not want the performance benefit of avoiding `return await`
51+
- If you want the functions to show up in stack traces (useful for debugging purposes)
4652

4753
## Further Reading
4854

0 commit comments

Comments
 (0)