Side navigation
#14724 closed bug (notabug)
Opened January 24, 2014 02:08AM UTC
Closed January 24, 2014 02:21AM UTC
Last modified January 24, 2014 09:29PM UTC
.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.
Attachments (0)
Change History (7)
Changed January 24, 2014 02:21AM UTC by comment:1
resolution: | → notabug |
---|---|
status: | new → closed |
Changed January 24, 2014 02:46AM UTC by comment:2
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.
Changed January 24, 2014 02:48AM UTC by comment:3
Did you read the documentation? Did you try what I described?
Changed January 24, 2014 02:58AM UTC by comment:4
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.
Changed January 24, 2014 03:01AM UTC by comment:5
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.
Changed January 24, 2014 04:22AM UTC by comment:6
jQuery
Deferredand
Promiseare 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
Changed January 24, 2014 09:29PM UTC by comment:7
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.
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?