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