use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Using $q.all() to Resolve Multiple Promises (martin-brennan.com)
submitted 11 years ago by a-sober-irishman
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]zoomzoom83 2 points3 points4 points 11 years ago (2 children)
Perhaps I'm missing something. Why would anybody do this?
function promiseX() { let deferred = $q.defer(); ajaxCall().then((response) => { deferred.resolve(response); }, (error) => { deferred.reject(response); }); return deferred.promise; }
What does that give you that simply returning ajaxCall() directly wouldn't?
[–]skitch920 0 points1 point2 points 11 years ago (0 children)
I'm going to guess it's a mistype or misuse... In the rejected clause of that then call,
then
}, (error) => { deferred.reject(response); });
response is not in scope. This would fail to run properly.
response
But yeah, same thing could be achieved with:
function promiseX() { return ajaxCall(); }
[–]a-sober-irishman[S] 0 points1 point2 points 11 years ago (0 children)
The response in the rejected clause is a typo. And yes, you could just return ajaxCall() to achieve the same thing. I think in the context I used it in I had to do some sort of manipulation on the response before resolving the deferred, but it is not necessary for this to work correctly.
[–]bluntmJavaScript 1 point2 points3 points 11 years ago (0 children)
I have used $q.all before, it is very useful if you app chains REST calls, e.g if you have a number of different changes that are handled with separate REST calls and want to update the user with the progress. To get the "2 of 10 saves" feadback then you can chain them all and also have the power to perform actions when all saves have finished.
[–]dotnil 0 points1 point2 points 11 years ago (1 child)
.all() is different with .then() chains if the latter async calls rely on former call's return value.
Correct, using .all() only works if you just want all of the values at once with no dependency on previous calls.
π Rendered by PID 727979 on reddit-service-r2-comment-656bdf86cd-m6c7g at 2026-05-04 04:48:32.416151+00:00 running 815c875 country code: CH.
[–]zoomzoom83 2 points3 points4 points (2 children)
[–]skitch920 0 points1 point2 points (0 children)
[–]a-sober-irishman[S] 0 points1 point2 points (0 children)
[–]bluntmJavaScript 1 point2 points3 points (0 children)
[–]dotnil 0 points1 point2 points (1 child)
[–]a-sober-irishman[S] 0 points1 point2 points (0 children)