1 # Disallow returning values from Promise executor functions (no-promise-executor-return)
3 The `new Promise` constructor accepts a single argument, called an *executor*.
6 const myPromise = new Promise(function executor(resolve, reject) {
7 readFile('foo.txt', function(err, result) {
17 The executor function usually initiates some asynchronous operation. Once it is finished, the executor should call `resolve` with the result, or `reject` if an error occurred.
19 The return value of the executor is ignored. Returning a value from an executor function is a possible error because the returned value cannot be used and it doesn't affect the promise in any way.
23 This rule disallows returning values from Promise executor functions.
25 Only `return` without a value is allowed, as it's a control flow statement.
27 Examples of **incorrect** code for this rule:
30 /*eslint no-promise-executor-return: "error"*/
32 new Promise((resolve, reject) => {
36 getSomething((err, result) => {
45 new Promise((resolve, reject) => getSomething((err, data) => {
58 Examples of **correct** code for this rule:
61 /*eslint no-promise-executor-return: "error"*/
63 new Promise((resolve, reject) => {
65 resolve(defaultResult);
68 getSomething((err, result) => {
77 new Promise((resolve, reject) => {
78 getSomething((err, data) => {
92 * [MDN Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
96 * [no-async-promise-executor](no-async-promise-executor.md)