node.js: while loop callback not working as expected

前端 未结 4 678
走了就别回头了
走了就别回头了 2021-02-06 04:36

Knowing that while Node.js is working asynchronously, writing something like this:

function sleep() {
    var stop = new Date().getTime();
    while(new Date().g         


        
4条回答
  •  被撕碎了的回忆
    2021-02-06 05:19

    As already mentioned, asynchronous execution should be achieved by setTimeout() rather than while, because while will freeze in one "execution frame".

    Also it seems you have syntax error in your example.

    This one works fine: http://jsfiddle.net/6TP76/

提交回复
热议问题