Skip to content

Latest commit

 

History

History
40 lines (28 loc) · 751 Bytes

es8.md

File metadata and controls

40 lines (28 loc) · 751 Bytes

Es8

Disallow await inside of loops

✅ Enabled (error)

// Bad
/*
async function foo(things) {
	const results = [];
	for (const thing of things) {
		// Bad: each loop iteration is delayed until the entire asynchronous operation completes
		results.push(await bar(thing));
	}
	return baz(results);
}
*/

// Good
async function foo(things) {
	const results = [];
	for (const thing of things) {
		// Good: all asynchronous operations are immediately started.
		results.push(bar(thing));
	}
	// Now that all the asynchronous operations are running, here we wait until they all complete.
	return baz(await Promise.all(results));
}