Skip to main content

Bug Tracker

Side navigation

#12770 closed bug (notabug)

Opened October 20, 2012 10:46AM UTC

Closed October 20, 2012 01:33PM UTC

Last modified October 20, 2012 01:41PM UTC

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.

Attachments (0)
Change History (2)

Changed October 20, 2012 01:33PM UTC by jaubourg comment:1

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 );

Changed October 20, 2012 01:41PM UTC by dmethvin comment:2

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().