Skip to main content

Bug Tracker

Side navigation

#11162 closed bug (duplicate)

Opened January 11, 2012 09:24PM UTC

Closed January 14, 2012 10:43AM UTC

Last modified January 14, 2012 10:43AM UTC

jQuery.when misbehaves with fail()

Reported by: anonymous Owned by: anonymous
Priority: low Milestone: None
Component: deferred Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:

This bug exists in 1.7.1 but dates back at least to 1.5.2.

   var deferred1 = $.Deferred();
   var deferred2 = $.Deferred(); {'1'); }); {'2'); });

   $.when(deferred1, deferred2).then(function() { }, function() {'3')});'ready');


The expected behavior would be to see "1 2 3" in the console. However the actual order is "1 3 2".

It looks like reject() triggers the when().fail() results eagerly. And while this example is a little contrived, this behavior also means that using when().always() for handling partial success doesn't work, because always() gets triggered before all of the requests have resolve()ed or reject()ed.

Attachments (0)
Change History (3)

Changed January 12, 2012 03:16PM UTC by timmywil comment:1

component: unfileddeferred
owner: → anonymous
priority: undecidedlow
status: newpending

Thanks for taking the time to contribute to the jQuery project! Please provide a complete reduced test case on jsFiddle to help us assess your ticket.

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate: Open the link and click to "Fork" (in the top menu) to get started.

Changed January 14, 2012 10:43AM UTC by jaubourg comment:2

resolution: → duplicate
status: pendingclosed

This is not a bug. $.when acts exactly like a logical AND. When one of the operands is false, then the result is false.

What happens here is exactly what you'd expect to happen when you write something like A && B in javascript when A is false: javascript won't even compute the B expression since the result is obligatory false no matter what.

Here, the promise returned by $.when will fail as soon as one of its arguments fails. It's exactly the same logic.

Keep in mind some promises can be pending forever: that way, you get failure as soon as possible (ie. as soon as only one promises fails).

I dunno of any logical operation equivalent for what you propose: that's a definite red flag for me.

Changed January 14, 2012 10:43AM UTC by jaubourg comment:3

Duplicate of #10836.