I am getting the error "callback is not defined" when trying to use async.parallel and but I am out of leads as to why. All the examples of async.parallel have the functions inline (like the async doco https://caolan.github.io/async/docs.html#parallel) but as the functions I want to run have some logic in them I have tried to split them out so they are not inline. This might be my problem but I think it should be possible, I just cannot figure out from the examples how the call backs should work in this situation.
Then intention here is to have two functions go get lists of IDs from different locations then put them together and do some things on the resulting array. I have trimmed the "go do other things" as it seems irrelevant at this stage.
var structuresIDArray = [];
function getPublicStructures(callback){
request({
url: 'https://esi.tech.ccp.is/latest/universe/structures/?datasource=tranquility',
method: 'GET'
}, function (error, response, body) {
if(!error && !body.error && response.statusCode === 200){
console.log('getting public locations');
structuresIDArray.concat(JSON.parse(body));
callback(null, structuresIDArray);
}else{
callback(error);
}
});
}
function getAssetLocationList(callback){
db.any('select distinct "location_id" from "public"."charassets" where "location_id" is not null')
.then(function (data) {
for (var i = 0; i < data.length; i++) {
structuresIDArray.push(data[i].location_id);
if(i+1===data.length){
callback(null, structuresIDArray);
}
}
})
.catch(function (err) {
callback(err);
});
}
function main(){
async.parallel([ getAssetLocationList(callback), getPublicStructures(callback) ],
function (err, results) {
if (err) {
throw err;
}
// Go do some other stuff now ...
});
}
via So Bad
No comments:
Post a Comment