Answer the question
In order to leave comments, you need to log in
How to execute n number of parallel requests using async?
Hello, how to execute the nth number of parallel requests using async, here is an example:
for (var i in data) {
request({
url: 'https://google.com',
agentClass: Agent,
agentOptions: {
socksHost: data[i].host,
socksPort: data[i].port
}
}, function(errChek, resChek) {
if (!errChek) {
data[i].status = true;
} else {
data[i].status = false;
}
})
}
Answer the question
In order to leave comments, you need to log in
async.times
async.each
async.each(data, (row, cb) => {
request({
url: 'https://google.com',
agentClass: Agent,
agentOptions: {
socksHost: row.host,
socksPort: row.port
}
}, (errChek, resChek) => {
row.status = !errChek;
return cb(null, row);
});
}, (err, results) => {
// complete
});
Either like this:
Or like this:
const p1 = callSomeAsyncFunction(),
p2 = callAnotherAsyncFunction(),
p3 = callAnotherAsyncFunction();
await p1;
await p2;
await p3;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question