noAsyncPromiseExecutor
Este conteúdo não está disponível em sua língua ainda.
Diagnostic Category: lint/suspicious/noAsyncPromiseExecutor
Since: v1.0.0
Sources:
- Same as:
no-async-promise-executor
Disallows using an async function as a Promise executor.
The executor function can also be an async function. However, this is usually a mistake, for a few reasons:
- 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. - If a Promise executor function is using
await
, this is usually a sign that it is not actually necessary to use thenew Promise
constructor, or the scope of thenew Promise
constructor can be reduced.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-block.js:1:13 lint/suspicious/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Promise executor functions should not be async
.
> 1 │ new Promise(async function foo(resolve, reject) {})
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
code-block.js:1:15 lint/suspicious/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Promise executor functions should not be async
.
> 1 │ new Promise(async (resolve, reject) => {})
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
code-block.js:1:19 lint/suspicious/noAsyncPromiseExecutor ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Promise executor functions should not be async
.
> 1 │ new Promise(((((async () => {})))))
│ ^^^^^^^^^^^^^^
2 │