Bug Tracker

Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#14724 closed bug (notabug)

.always() does not wait for .fail()

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

Description

See this fiddle: http://jsfiddle.net/9TtkL/1/

If you have a promise chain that ends in .fail(...).always(...) and a promise is returned from fail, always is supposed to wait for that promise to finish before executing. It does not.

If you open the console on the jsFiddle, you can see that "fail" and "always" are logged instantly, even though the fail call returns a timeout delay.

Then a Q promise is kicked off to show the correct behavior. Promises always chain off of their return values, and always() is supposed to chain off of promises returned from fail().

The jsFiddle uses this version of jQuery: jQuery.fn.jquery 2.1.1pre 4655c3de5f0348da25452ea64d80613bf919284e

I can confirm it goes as far back as 1.8.2, possibly all versions of jQuery.

Change History (7)

comment:1 Changed 6 years ago by dmethvin

Resolution: notabug
Status: newclosed

That's not the way .fail() works. It adds a handler to the existing promise, and does not create a new one.

http://api.jquery.com/deferred.fail/

I think you are looking for .then(null, handler) perhaps?

comment:2 Changed 6 years ago by anonymous

Promises allow you to add to the "chain" by returning promises inside handlers. That is how promises (including fail) work - you can see that Q handles the case correctly.

comment:3 Changed 6 years ago by dmethvin

Did you read the documentation? Did you try what I described?

comment:4 Changed 6 years ago by anonymous

The documentation makes no specific mention of this case. It also does not seem like the A+ spec even mentions fail and always handlers.

.then( pass, fail ) is unrelated to the issue. It is odd that fail and always are treated with an entirely different promise api than then.

comment:5 Changed 6 years ago by dmethvin

The documentation for deferred.fail() says: "Add handlers to be called when the Deferred object is rejected."

That seems pretty clear to me. It's adding handlers to the object that the method is called upon. If you need further help, please ask for it on StackOverflow.

comment:6 Changed 6 years ago by d.wachss@…

jQuery Deferred and Promise are not A+ Promises; they are "thenable"s in the sense of the spec http://promises-aplus.github.io/promises-spec/ and can be cast to Promises. The almost-but-not-quite similarity is confusing; see https://github.com/kriskowal/q/wiki/Coming-from-jQuery

comment:7 Changed 6 years ago by anonymous

I see. jQuery promises aren't actually promises. Very disturbing because they advertise them as such. I will use Q in the browser. Thank you.

Note: See TracTickets for help on using tickets.