Reputation: 2467
Can anyone tell me whats wrong with the code when calling promise with map? I get undefined output. P.S this is for meteor.
async function getResUrl(item, url){
let res = await HTTP.call("GET", url, function(err, res){
return res.statusCode;
});
console.log(res);
return res;
}
function getUrlRes(_screenName) {
let getRes = Promise.all(_.map(Object.keys(social), function(item){
let url = social[item]+"/"+_screenName;
getResUrl(item, url);
})).then(function(result){
return result
});
return getRes;
}
Upvotes: 0
Views: 2359
Reputation: 707856
Assuming getResUrl()
returns a promise, change this:
getResUrl(item, url);
to
return getResUrl(item, url);
You have to return the promise so map()
can accumulate the promises.
It looks like you also may need to properly promisify HTTP.call()
so that it returns a promise.
Upvotes: 3