Reputation: 8232
I'm looking into BreezeJs and there samples are using Q.js for promises to handle asynchronous calls. John Papa is also using Q. JQuery has promises as well. What are the differences between the two?
Upvotes: 34
Views: 13464
Reputation: 112817
Bergi's answer covers things fairly well. I wanted to add, though, that we've created a guide for Q users coming from jQuery. To summarize the relevant sections:
then
/pipe
.this
in which the caller must run). So there is no resolveWith
or rejectWith
.The guide also contains a table paralleling jQuery and Q promise APIs.
Upvotes: 13
Reputation: 664256
Both are based on the Promises/A standard and implement a then
method (though only current jQuery, they once had a incompatible pipe
instead of then
). However, there are a few differences:
then
callbacks will be caught and reject the promise (and will only get re-thrown if you call .end()
). Not sure whether I personally like that. It's the standardized way which jQuery does not follow, rejecting from then
in jQuery deferreds is much more complicated.then
), while jQuery allows multiple arguments in resolve
/reject
calls on its Deferreds..all
and similiar, which are more complicated with jQuery ($.when.apply($, […])
).… which is basically Promises/B. As you can see, the Q
API is more powerful, and (imho) better designed. Depending on what you want to do, Q
could be the better choice, but maybe jQuery (especially if already included) is enough.
Upvotes: 48
Reputation: 17052
JQuery's promise implementation of the Promises/A spec has some real issues. The following link describes them far better than I can: missing-the-point-of-promises
Upvotes: 17