In Angular at the moment I have this:
app.factory("myService", function($http, $q) {
return {
doBoth: function(data) {
return $q.all([$http.post("/search/local", data), $http.post("/search/shape", data)]);
}
};
});
and i call it like this:
$scope.$on("localSearch", function(event, data) {
return myService.doBoth(data);
});
However I do not think it is happening asynchronously. They both take quite a time to get fulfilled so I need Angular to request both at the same time, so the complete request isn't one + the other - but the quickest time they both get returned in.
If you want to fire callback after both queries completed, place it in $q.then() method.
$scope.$on("localSearch", function(event, data) {
return myService
.doBoth(data)
.then(function (response) {
// both deffered completed
});
});
I've created sample here http://plnkr.co/edit/7G8oFMSx8cPC98zDhlNq?p=preview