π Disallow using await in Promise method parameters.
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π‘ This rule is manually fixable by editor suggestions.
Using await on promises passed as arguments to Promise.all(), Promise.allSettled(), Promise.any(), or Promise.race() is likely a mistake.
This also applies to await nested inside an element, since it delays the evaluation of the elements after it.
When an operation depends on an awaited value, wrap it in an async immediately invoked function expression (IIFE) to allow array construction to continue without waiting for that value.
// β
Promise.all([await promise, anotherPromise]);
// β
Promise.all([promise, anotherPromise]);// β
Promise.allSettled([await promise, anotherPromise]);
// β
Promise.allSettled([promise, anotherPromise]);// β
Promise.any([await promise, anotherPromise]);
// β
Promise.any([promise, anotherPromise]);// β
Promise.race([await promise, anotherPromise]);
// β
Promise.race([promise, anotherPromise]);// β
Promise.all([(await promise).foo, anotherPromise]);
// β
Promise.all([promise.then(value => value.foo), anotherPromise]);// β
Promise.all([condition ? await promise : fallbackPromise, anotherPromise]);
// β
Promise.all([condition ? promise : fallbackPromise, anotherPromise]);// β
Promise.all([
(await fetch(url)).json(),
...otherPromises,
]);
// β
Promise.all([
(async () => (await fetch(url)).json())(),
...otherPromises,
]);