2 title: no-async-promise-executor
9 The `new Promise` constructor accepts an *executor* function as an argument, which has `resolve` and `reject` parameters that can be used to control the state of the created Promise. For example:
12 const result = new Promise(function executor(resolve, reject) {
13 readFile('foo.txt', function(err, result) {
23 The executor function can also be an `async function`. However, this is usually a mistake, for a few reasons:
25 * If an async executor function throws an error, the error will be lost and won't cause the newly-constructed `Promise` to reject. This could make it difficult to debug and handle some errors.
26 * If a Promise executor function is using `await`, this is usually a sign that it is not actually necessary to use the `new Promise` constructor, or the scope of the `new Promise` constructor can be reduced.
30 This rule aims to disallow async Promise executor functions.
32 Examples of **incorrect** code for this rule:
37 const foo = new Promise(async (resolve, reject) => {
38 readFile('foo.txt', function(err, result) {
47 const result = new Promise(async (resolve, reject) => {
54 Examples of **correct** code for this rule:
59 const foo = new Promise((resolve, reject) => {
60 readFile('foo.txt', function(err, result) {
69 const result = Promise.resolve(foo);
76 If your codebase doesn't support async function syntax, there's no need to enable this rule.