Is that possible with asyncjs?
yes, it is possible., like this
1.
var async = require('async');
var urls = ['http://google.com', 'http://amazon.com', 'http://bing.com'];
function readUrl(url, next) {
// some code
next(null, result);
}
urls = urls.map(function(url) {
return function (next) {
readUrl(url, next);
};
});
async.parallel(urls, function(err, res) {
console.log(err, res);
})
2.
var async = require('async');
var urls = ['http://google.com', 'http://amazon.com', 'http://bing.com'];
function readUrl(url) {
return true;
}
urls = urls.map(function(url) {
return function (next) {
var res = readUrl(url);
if (res) {
return next(null, res);
}
next('Error');
};
});
async.parallel(urls, function(err, res) {
console.log(err, res);
})
urls.forEach(readUrl). Presumably you're interested in doing something more interesting, such as running them in sequence, or running them in parallel and waiting until all they finish, or...?? Also, what doesreadUrldo--does it return a promise, because otherwise, with no callback visible in your example, there will be no way to tell if it's done at all.