Bug Tracker

Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#12770 closed bug (notabug)

Promises .done() should chain just like .then()

Reported by: edwinm Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


jQuery version 1.8.2.

According to the documentation, the done() and then() functions from the Promises interface are chainable.

For then(), this is already fixed (#11010).

done() still can't be chained.

So, this code works properly:


fn2() is executed after the promise of fn1() is resolved.

And this does not work:


fn2() is executed immediately, ignoring the promise of fn1().

I created a JSFiddle to show this:


Being able to execute promises sequentially is a basic functionality of Promises.

Change History (2)

comment:1 Changed 10 years ago by jaubourg

Resolution: notabug
Status: newclosed

Having to create an internal Deferred in order to enable queueing in then is quite expensive. done, fail and progress can accept multiple callbacks and return the original Deferred/Promise (whichever object the method is attached to actually). That makes the latters an very efficient means to attach callbacks to a Promise. They don't "chain" on purpose. Actually, I'm wondering if you're not confusing chaining (in the jQuery sense of the term) and queueing (what chaining in the Promise sense of the term actually means). If the documentation is not clear enough, we probably need to fix that..

Anyway, what is the problem with simply using the following?

promise.then( fn1 ).then( fn2 );

comment:2 Changed 10 years ago by dmethvin

I think the main problem is documentation; there is already a ticket to fix that in the docs tracker. We changed .then() to act the same as Promise/A and provide some level of interoperability. We definitely do not want to change .done() because, as you say, it is much more efficient when all you want to do is attach some more handlers for the original promise--e.g., $(document).ready().

Note: See TracTickets for help on using tickets.