I have a bunch of functions used to provide data to my service. I want to loop through each of them and stop as soon as one of them returns the desired result. If the first one
if promises are not a hard constraint caolan/async#eachSeries or similar might help. Something like...
// var Promise = require(?)
// var async = require("async")
handleData: asyncProviderFinder
...
function asyncProviderFinder(address){
var self = this;
return new Promise(function(resolve, reject){
async.eachSeries(
self.listAllAvailableProviders,
function iterate(provider, next){
var handler = provider;
new handler().getData(address)
.then( function(value){
Logger.info(value);
next("abort"); // callback any error to abort future iterations
return resolve(value);
})
.catch( function (err){
Logger.error(err);
next();
});
},
function callback(err, firstProvider){
if ((firstProvider === undefined) && !err ){ reject(""); }
}
);
});
}