1 sleep = (milliseconds) => {
2 return new Promise(resolve => setTimeout(resolve, milliseconds))
3 }
4
5 componentDidUpdate(prevProps, prevState, snapshot) {
6 this.sleep(5000).then(r => {
7 // do something
8 })
9 }
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));