延迟节点js在特定时间执行

时间:2015-06-01 18:46:43

标签: javascript node.js loops

我使用这个脚本:

var i = 0;
async.whilst(
    // test to perform next iteration
    function() { return i <= Myobject.length-1; },
    function(innerCallback){
//Some calculations....
setTimeout(function() { i++; innerCallback(); }, 10000);
  };
);

上面的代码段会延迟循环元素之间的执行10秒钟。但是我怎样才能在specific time延迟循环执行几秒钟? 任何建议都非常感谢!

1 个答案:

答案 0 :(得分:0)

var delayInterval = 10000;

setTimeout(function(){
  delayInterval = 30000;
}, 1000*60*30);

var i = 0;
async.whilst(
    // test to perform next iteration
    function() { return i <= Myobject.length-1; },
    function(innerCallback){
//Some calculations....
setTimeout(function() { i++; innerCallback(); }, delayInterval );
  };
);