📜  javascript 睡眠功能 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:23.788000             🧑  作者: Mango

代码示例6
sleep = milliseconds => new Promise(resolve => setTimeout(resolve, milliseconds));

//        V  Must add this async keyword
sayHi = async () => {
      // V Must include await
    await sleep(1000); // Sleep 1000 milliseconds (1 second)
      console.log('Hi');
      // Rest of code...
}