Skip to content

noAwaitInPromiseMethods (JavaScript)

Language JavaScript (and super languages)
biome.json
{
"linter": {
"rules": {
"nursery": {
"noAwaitInPromiseMethods": "error"
}
}
}
}

Disallow using await inside the array passed to Promise.all(), Promise.allSettled(), Promise.any(), or Promise.race().

These methods wait for several promises at the same time. Using await while building the array pauses the code until that promise finishes. The rest of the array, and the method call itself, can only run after that, so the promises no longer run at the same time.

If an element needs an awaited value, move the await into an async function and call it right away, or use .then(). Both create a promise without pausing the code.

Promise.all([await promise, anotherPromise]);
code-block.js:1:14 lint/nursery/noAwaitInPromiseMethods  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This await delays the call to Promise.all().

> 1 │ Promise.all([await promise, anotherPromise]);
│ ^^^^^^^^^^^^^
2 │

ℹ The rest of the array and the call to Promise.all() have to wait until this promise finishes, so the promises don't run at the same time.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

ℹ Unsafe fix: Remove the await.

1 │ Promise.all([await·promise,·anotherPromise]);
│ ------
Promise.race([condition ? await promise : fallbackPromise, anotherPromise]);
code-block.js:1:27 lint/nursery/noAwaitInPromiseMethods ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This await delays the call to Promise.race().

> 1 │ Promise.race([condition ? await promise : fallbackPromise, anotherPromise]);
│ ^^^^^^^^^^^^^
2 │

ℹ The rest of the array and the call to Promise.race() have to wait until this promise finishes, so the promises don't run at the same time.

ℹ Move the await into an async function that you call right away, or use .then() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Promise.all([(await fetch(url)).json(), anotherPromise]);
code-block.js:1:15 lint/nursery/noAwaitInPromiseMethods ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

⚠ This await delays the call to Promise.all().

> 1 │ Promise.all([(await fetch(url)).json(), anotherPromise]);
│ ^^^^^^^^^^^^^^^^
2 │

ℹ The rest of the array and the call to Promise.all() have to wait until this promise finishes, so the promises don't run at the same time.

ℹ Move the await into an async function that you call right away, or use .then() instead.

ℹ This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit https://biomejs.dev/linter/#nursery for more information.

Promise.all([promise, anotherPromise]);
Promise.allSettled([promise.then((value) => value.foo), anotherPromise]);
Promise.any([(async () => (await fetch(url)).json())(), anotherPromise]);