1function sleep(ms) {
2 return new Promise(resolve => setTimeout(resolve, ms));
3}
4
5console.log("Hello");
6sleep(2000).then(() => { console.log("World!"); });
7
1 async function delay(delayInms) {
2 return new Promise(resolve => {
3 setTimeout(() => {
4 resolve(2);
5 }, delayInms);
6 });
7 }
8 async function sample() {
9 console.log('a');
10 console.log('waiting...')
11 let delayres = await delay(3000);
12 console.log('b');
13 }
14 sample();