Skip to content

Latest commit

Β 

History

History
80 lines (58 loc) Β· 1.88 KB

no-await-in-promise-methods.md

File metadata and controls

80 lines (58 loc) Β· 1.88 KB

no-await-in-promise-methods

πŸ“ 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.

Examples

// ❌
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,
]);