node.js - nodejs如何同步延迟运行函数
PHP中文网
PHP中文网 2017-04-17 15:54:35
0
3
457

队列示例

var array = [1,2,3,4];
function check()
{
if(array.length > 0)
var url = array.pop();
load(url);
}}
function load(url)
{
http.get(url, function(res){
check();
)
}}

我想在 每次load(url)的时候 延迟6秒 这时候我用setTimeout 没什么效果

PHP中文网
PHP中文网

认证0级讲师

reply all(3)
巴扎黑

Use sleep

黄舟
  1. It’s best to format it when sending the code! Dear

  2. If you use setTimeout to implement it, you need to recurse

PHPzhong

The timing function can be written like this

    var a = function(){
        //逻辑
        setTimeout(() => {
            a()
        }, time)
    }

I don’t know if that’s what you want

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template