Share a small interview question

Fill in the blanks with the code and complete the specified function

    function sleep(time) {
      let t = new Promise((resolve, reject) => {
        setTimeout(() => {
          resolve()
        }, time);
      })
      return t
    }
    sleep(2000).then(() => {
      console.log('后续操作');
    })

The goal is to make sleep function the same as setTimeout, which is to wait 2000 milliseconds before performing subsequent operations

Guess you like

Origin blog.csdn.net/m0_67296095/article/details/124526734