Looking to filter an array based on a condition that requires asynchronous checking.
return someList.filter(function(element){
//async process here
})
Any better way to achieve this using promises?
This code snippet utilizes Q for handling promises, but it can be adapted to any other promises implementation as well.
return q.all(someList.map(function (listElement) {
return promiseMeACondition(listElement.entryId).then(function (condition) {
if (condition) {
return q.fcall(function () {
return listElement;
});
} else {
return q.fcall(function(){});
}
});
}));
The above code snippet successfully resolves the promises and filters the array accordingly.