unicorn/no-await-in-promise-methods
Disallow await on the elements of the array passed to Promise.all() and similar methods
has suggestions
Promise.all([await loadUser(), await loadPosts()]) waits for the user before it starts loading the posts. The requests run one after the other, and Promise.all() only gets finished values, so it has nothing left to do. With Promise.race() and Promise.any(), there's no race either.
The rule checks Promise.all(), Promise.allSettled(), Promise.any(), and Promise.race().
--fix-suggestions removes the await.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"unicorn/no-await-in-promise-methods" = "error" # or "warn"Examples#
example.js2 problems
async function loadPage(id) {
const [user, posts] = await Promise.all([awaitPromise in Promise.all() should not be awaited. loadUser(id), awaitPromise in Promise.all() should not be awaited. loadPosts(id)]);
render(user, posts);
}example.jsNo problems
async function loadPage(id) {
const [user, posts] = await Promise.all([loadUser(id), loadPosts(id)]);
render(user, posts);
}