In JavaScript, a promise is a mechanism to perform tasks in an asynchronous way. To this end, the language provides the Promise object which represents the eventual completion or failure of an asynchronous operation and its resulting value. A promise can be created with the Promise constructor accepting an executor function as an argument, which has resolve and reject parameters that are invoked when the promises completes or fails.

Why is this an issue?

The executor function of a promise can also be an async function. However, this usually denotes a mistake:

How to fix it

Fixing the issue requires removing the async keyword from the Promise executor function and adapting the body of the executor accordingly.

Code examples

Noncompliant code example

const p = new Promise(async (resolve, reject) => {
  doSomething('Hey, there!', function(err, res) {
    if (err) {
      reject(err);
      return;
    }
    await saveResult(res)
    resolve(res);
  });
});

await p;

Compliant solution

const p = new Promise(async (resolve, reject) => {
  doSomething('Hey, there!', function(err, res) {
    if (err) {
      reject(err);
      return;
    }
    resolve(res);
  });
});

const res = await p;
await saveResult(res);

Resources

Documentation