如何使用公共回调从 nodejs 服务器进行多个 http 调用?
How to make multiple http calls from the nodejs server with a common callback?
我想在节点 js 服务器中使用公共回调进行多个 http 调用。
有没有可用的模块?
您可以使用异步库或下划线。
我经常为此使用下划线。假设您正在进行 n 个 http 调用
var http_done = _.after(n, function() {
// final callback
});
for... {
ajax_call(..., function(response) {
// Do something with response
http_done();
});
}
我已经使用这个 Async NPM 来解决这个问题。
https://www.npmjs.com/package/async
async.parallel([
function(callback){
callback(null,1)
},
function(callback){
callback(null,2)
},
],
function(err, results){
console.log(results); //Output [1,2]
});
我想在节点 js 服务器中使用公共回调进行多个 http 调用。 有没有可用的模块?
您可以使用异步库或下划线。
我经常为此使用下划线。假设您正在进行 n 个 http 调用
var http_done = _.after(n, function() {
// final callback
});
for... {
ajax_call(..., function(response) {
// Do something with response
http_done();
});
}
我已经使用这个 Async NPM 来解决这个问题。 https://www.npmjs.com/package/async
async.parallel([
function(callback){
callback(null,1)
},
function(callback){
callback(null,2)
},
],
function(err, results){
console.log(results); //Output [1,2]
});