Skip to content

Latest commit

 

History

History
37 lines (25 loc) · 952 Bytes

prefer-await-to-callbacks.md

File metadata and controls

37 lines (25 loc) · 952 Bytes

Prefer async/await to the callback pattern (promise/prefer-await-to-callbacks)

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:

cb()
callback()
doSomething(arg, (err) => {})
function doSomethingElse(cb) {}

Examples of correct code for this rule:

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