2 title: no-async-promise-executor
8 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:
11 const result = new Promise(function executor(resolve, reject) {
12 readFile('foo.txt', function(err, result) {
22 The executor function can also be an `async function`. However, this is usually a mistake, for a few reasons:
24 * 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.
25 * 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.
29 This rule aims to disallow async Promise executor functions.
31 Examples of **incorrect** code for this rule:
36 const foo = new Promise(async (resolve, reject) => {
37 readFile('foo.txt', function(err, result) {
46 const result = new Promise(async (resolve, reject) => {
53 Examples of **correct** code for this rule:
58 const foo = new Promise((resolve, reject) => {
59 readFile('foo.txt', function(err, result) {
68 const result = Promise.resolve(foo);
75 If your codebase doesn't support async function syntax, there's no need to enable this rule.