Skip to main content

Bug Tracker

Side navigation

#11283 closed bug (invalid)

Opened February 06, 2012 02:27PM UTC

Closed February 06, 2012 02:30PM UTC

Deferred object resolution.

Reported by: yandreyev@yahoo.com Owned by:
Priority: low Milestone: None
Component: deferred Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
Description

When deferred object is in a process of handing '.done' handers, if I attach another '.done' is it by intentional design that the new 'done' handler attached to a resolved object is handled last?

Here's the case...

// NORMAL CASE

var def = $.Deferred().resolve()

def.done(function() {

console.log("This line executes FIRST as expected.")

});

console.log("This line executes LAST as expected.");

IS THIS RIGHT? /

var def= $.Deferred();

setTimeout(function() {

def.resolve();

},300)

def.done(function() {

def.done(function() {

console.log("shouldn't this line come FIRST?")

})

console.log("shouldn't this line come LAST?")

})

Here's how this is relevant to a project I'm involved in. I need to ensure that a set of deferred objects, are all resolved at a certain point in the process. These objects can be resolved or reset (back to pending) at independent locations in the code. For this I use a convenient $.when construct. And to ensure that deferred objects are all resolved at that point I again, invoke the same $.when -- thus if all are resolved I expect '.done' to process immediately. Here's the mockup...

var test = function() {

var testAgain = false;

$.when(def1, def2, def3).done(function() {

if (testAgain) {

test();

return;

}

/ ALL RESOLVED CONTINUE WITH PROCESS. /

....

....

});

testAgain = true;

}

test();

Attachments (0)
Change History (1)

Changed February 06, 2012 02:30PM UTC by sindresorhus comment:1

component: unfileddeferred
priority: undecidedlow
resolution: → invalid
status: newclosed

Thanks for taking the time to try to contribute to the jQuery project but this is not a valid bug. This bug tracker is not a support forum, and is only for solving reproducible, verifiable bugs with jQuery Core itself.

If you require assistance with your code, please make a post in either the official jQuery Forums or on our #jquery channel on freenode. Should you be able to establish that the issue you are seeing is in fact related to core and can be reduced, we will me more than happy to investigate further at that point.