Ticket #10467 (closed feature: wontfix)
Deferreds should always resolve asynchronously
| Reported by: | scott.gonzalez | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | 1.9 |
| Component: | deferred | Version: | 1.6.4 |
| Keywords: | 1.8-discuss | Cc: | |
| Blocking: | #12044 | Blocked by: | #11013 |
Description (last modified by rwaldron) (diff)
Deferreds should always be resolved asynchronously. Any abstraction that deals with a potentially async operation should always act asynchronously. The current implementation prevents users from writing code that takes advantage of async behavior and can cause bugs in bad code that is written against an initially synchronous implementation that later becomes asynchronous.
This also has the (positive) side effect of cached XHR requests in IE being resolved asynchronously.
Change History
comment:1 Changed 20 months ago by scott.gonzalez
- Component changed from unfiled to deferred
- Summary changed from Deferreds should should always resolve asynchronously to Deferreds should always resolve asynchronously
comment:2 Changed 20 months ago by jaubourg
I agree, but async=false in $.ajax() disagrees.
If we want to make Deferred 100% asynchronous, then we have to remove synchronous ajax requests (which I'd love to be able to do btw, but I doubt I'll see the day).
comment:3 Changed 20 months ago by scott.gonzalez
Do we know if there's a lot of use of deferreds on sync XHR requests?
If we can't always force deferreds to resolve asynchronously, can we at least have an option during creation of the deferred for whether or not it should be forced to be async, with the default being async? Then sync XHR can set the flag and continue working as it does today.
comment:5 Changed 20 months ago by jaubourg
OK, so this is clearly about changing behaviour... do I wait for 1.8 for trying and fixing it or do I try it for 1.7? (async option was something I intended to add in $.Callbacks later on FYI)
comment:6 Changed 18 months ago by jaubourg
- Keywords 1.8-discuss added
- Priority changed from undecided to low
- Blocked by 11013 added
- Milestone changed from None to 1.8
comment:9 Changed 18 months ago by timmywil
+0, As I understand it, we are sometimes dependent on the synchronous nature of certain deferreds.
comment:11 Changed 13 months ago by gnarf
I'm against this at this point, I can't use Deferred in animate any longer if it becomes async. No matter what we end up doing, It would break at least two use cases within jQuery core to not somehow still support the sync behavior.
comment:12 Changed 12 months ago by gnarf
I retract my earlier complaint under the assumption that this only causes a "async" step if it is resolved/rejected in the same event loop it was created in.
comment:13 Changed 12 months ago by scott.gonzalez
@gnarf That is my intention. If the deferred is resolved in a future tick then the callbacks should be invoked in that same tick (synchronous with the resolution, but asynchronous compared to the creation of the deferred).
comment:14 Changed 12 months ago by dmethvin
- Milestone changed from 1.8 to 1.9
Pushing to 1.9, current plan is to move the now-deprecated async:false option to a compat plugin which would allow $.Deferred to be totally async.
comment:15 Changed 11 months ago by tj@…
+1, if a callback may occur asynchronously to the code hooking it up, it should always occur asynchronously to that code. In fact, I recently file ticket #12044 because ready is chaotic in this respect.
comment:16 Changed 9 months ago by dmethvin
- Type changed from enhancement to feature
Bulk change from enhancement to feature.
comment:18 Changed 6 months ago by dmethvin
- Status changed from open to closed
- Resolution set to wontfix
In the email thread we had, it seemed like there was just too much potential for breaking lots of code (including cases currently in our own ajax and effects) so I don't think we can do this. Note that the Promise/A discussion leaves this intentionally unspecified.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.
