Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 997 Bytes

prefer-top-level-await.md

File metadata and controls

49 lines (38 loc) · 997 Bytes

Prefer top-level await over top-level promises and async function calls

💼 This rule is enabled in the ✅ recommended config.

💡 This rule is manually fixable by editor suggestions.

Top-level await is more readable and can prevent unhandled rejections.

Fail

(async () => {
	try {
		await run();
	} catch (error) {
		console.error(error);
		process.exit(1);
	}
})();
run().catch(error => {
	console.error(error);
	process.exit(1);
});
async function main() {
	try {
		await run();
	} catch (error) {
		console.error(error);
		process.exit(1);
	}
}

main();

Pass

await run();