setTimeout happens only once in a loop expression

后端 未结 7 1316
耶瑟儿~
耶瑟儿~ 2021-01-24 23:35

This is an example:

function func1()
{
   setTimeout(function(){doSomething();}, 3000);
}
for(i=0;i<10;i++)
{
   func1();
}

after executing

7条回答
  •  灰色年华
    2021-01-24 23:48

    With async.js:

    async.timesSeries(5, function (n, next) {
        setTimeout(function(){
            doSomething();
            next();
        }, 3000);
    });
    

提交回复
热议问题