# no-async-promise-executor

Disallow async functions as promise executors.

Promise executors are special functions inside new Promise() constructors which take a resolve and reject parameter to resolve or reject the promise. The function is a normal function therefore it could be an async function. However this is usually wrong because: - Any errors thrown by the function are lost. - It usually means the new promise is unnecessary.

# Incorrect code examples

let foo = new Promise(async (resolve, reject) => {
    doSomething(bar, (err, res)) => {
       /* */
    });
});
let foo = new Promise(async function(resolve, reject) => {
    /* */
});

# Correct code examples

Use a normal non-async function.

let foo = new Promise(function(resolve, reject) => {
    /* */
})
More incorrect examples
new Promise(async () => {})
new Promise(async function*() {})
new Promise(async function() {}, foo)
More correct examples
new Promise(() => {})
new Promise(function foo() {}, foo)

Source (opens new window)

Last Updated: 11/18/2020, 9:36:33 PM