1async function init() {
2 console.log(1);
3 await sleep(1000);
4 console.log(2);
5}
6
7function sleep(ms) {
8 return new Promise((resolve) => {
9 setTimeout(resolve, ms);
10 });
11}
12
13// one liner
14let sleep = ms => new Promise(resolve => setTimeout(resolve, ms));