Rule change request: no-async-promise-executor should be if-async-promise-executor-then-try-catch-surrounding-await
See original GitHub issueWhat rule do you want to change? no-async-promise-executor
Does this change cause the rule to produce more or fewer warnings? Same result with fewer warnings
How will the change be implemented? (New option, new default behavior, etc.)? New default behavior
Please provide some example code that this change will affect:
new Promise(async (resolve, reject) => {
try {
const someValue = await someAsyncMethod()
const someOtherValue = await someOtherAsyncMethod()
return resolve(someValue + someOtherValue)
} catch (error) {
return reject(error)
}
})
What does the rule currently do for this code? Warns with Promise executor functions should not be async.
What will the rule do after it’s changed? I think this rule should allow async executors whenever the await
calls are within a try/catch block and promise is resolved/rejected accordingly, something like if-async-promise-executor-then-try-catch-surrounding-await
. As it is, this rule is forcing me to write the above code using .then()
constructs which I don’t prefer. This will still prevent situations where async executors falls into the wrong pattern (i.e. resolving/rejecting synchronously).
Are you willing to submit a pull request to implement this change? Yes
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (3 by maintainers)
Could you replace your code with this instead?
That would have the same behavior. It seems like using the
Promise
constructor is unnecessary if you’re already using async functions to produce the result.