Node.js 返回最后一个呼叫并在5秒内退出节点

Node.js 返回最后一个呼叫并在5秒内退出节点,node.js,process,polling,Node.js,Process,Polling,我正在尝试查看节点在5秒内可以发出多少请求。我希望所有的电话都能在5秒内回复。“opt”是链接数组 function poll() { async.each(opt, function(entry, callback) { count1++; request({uri:entry, method: "GET",pool:pool}, function(error, response, body) {

我正在尝试查看节点在5秒内可以发出多少请求。我希望所有的电话都能在5秒内回复。“opt”是链接数组

    function poll()
{
     async.each(opt, function(entry, callback) {
                count1++;
                request({uri:entry, method: "GET",pool:pool}, function(error, response, body) {
                     count++;
                if(Math.abs(new Date()-d)==5000)
                {

                    process.exit(1);
                }
                if (!error && response.statusCode == 200) {

                    console.log('Yes '+entry);
                    countYes++;
                }
                else {
                    console.log('No '+entry);
                    countNo++;
                }
               callback();
            });
        }, function(err) {
                            count1--;
                            if(count1==0)  
                                console.log(d+" "+new Date()+"\nTotal "+count+" \nNo"+countNo+" \nYes"+countYes+"/n Duration="+Math.abs(new Date()-d));
        }); 
}

function req() {
    var myDate2=new Date();
    myDate2.setSeconds(myDate2.getSeconds()+5);
    //  console.log(d);
    while(true)
    {
        var d=new Date();
        poll();
        if(d>myDate2)
        {
            break;
        } 



       }

}
req(); 

最后一个调用应在5秒钟后返回,节点应退出。

setTimeout可能是您的朋友,在这里…并发连接,串联?请指定。。。您可以使用
ab
por实现此目的。@hereandnow78-我尝试过这样做,但异步调用在5秒后返回很多(节点不退出)。