-
-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
37 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,37 @@ | ||
# Prefer async/await to the callback pattern (`promise/prefer-await-to-callbacks`) | ||
# Prefer `async`/`await` to the callback pattern (`promise/prefer-await-to-callbacks`) | ||
|
||
<!-- end auto-generated rule header --> | ||
|
||
`async`/`await` is a clearer pattern to follow than using callbacks. | ||
|
||
## Rule details | ||
|
||
ES2017's `async`/`await` makes it easier to deal with asynchronous code than the | ||
callback pattern. | ||
|
||
Examples of **incorrect** code for this rule: | ||
|
||
```js | ||
cb() | ||
callback() | ||
doSomething(arg, (err) => {}) | ||
function doSomethingElse(cb) {} | ||
``` | ||
|
||
Examples of **correct** code for this rule: | ||
|
||
```js | ||
await doSomething(arg) | ||
async function doSomethingElse() {} | ||
yield yieldValue(err => {}) | ||
eventEmitter.on('error', err => {}) | ||
``` | ||
|
||
## When Not To Use It | ||
|
||
If you are not targeting an ES2017 or higher environment and cannot transpile | ||
`async`/`await`, you should disable this rule. | ||
|
||
## Further Reading | ||
|
||
- [Making asynchronous programming easier with async and await on MDN](https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Asynchronous/Promises) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters