setTimeout behaviour with blocking code

后端 未结 4 1437
无人及你
无人及你 2020-11-29 08:01

This is my test code (fiddle here):

console.log(\'Before wait\');
setTimeout(function () { console.log(\'Yo!\'); }, 1000);
var start = Date.now();
while (Dat         


        
4条回答
  •  情话喂你
    2020-11-29 08:16

    Not sure if it could help you but this problem's been explained in: https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop#Run-to-completion

    For this reason, the second argument indicates a minimum time—not a guaranteed time.

提交回复
热议问题