async function main() { console.log('begin'); await wait(2000); console.log('end'); } function wait(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } main().then(() => console.log('main is done'));