//这个东西不会睡是十秒,因为异步执行了

console.log("sleep start")

setTimeout(function(){

},10000)

console.log("sleep over")

正确的阻塞10秒的方法是下边这样的

    function sleep(milliSeconds){
        console.log("sleeping")
        function _getTime(){
            return new Date().getTime();
        }
        var start = _getTime();
        while(_getTime()<start+milliSeconds);
    }
   sleep(10000)

这个玩意,放在哪里都会睡着10秒绝对堵着

 

相关文章:

  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-06
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-05-26
  • 2022-02-13
相关资源
相似解决方案