Skip to content

$.when should always be synchronous when possible #3100

Closed
@marcandre

Description

IIC, jQuery 3.0 will have then be A+ compatible in that callbacks are always executed out of context (e.g with setTimeout), while done will continue to be executed synchronously whenever possible (eager).

I was double checking that $.when kept the eager behavior and discovered that it does, unless there's a single argument:

p = $.Deferred()
p.resolveWith(42);
p.done(function() {console.log('A')});
$.when(p).done(function() {console.log('B')});
$.when(p, p).done(function() {console.log('C')});
console.log('D');

I was hope to get ABCD, given that the promised is already resolved when the done are called, and dreaded ADBC if $when was no longer eager. I get worse though. Console is ACDB, which is not acceptable; $.when(p) and $.when(p, p) should behave the exact same way.

FWIW, I personally disagree with Promise/A+'s rule 2.2.4 and I hope jQuery keeps all behavior eager (except for then to comply with A+) and gives us an eager version of then (could be pipe, but with the correct semantics for callbacks return values).

I did not investigate any further, but it looks related to #3059.

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions