Reputation: 8524
I'm new to jquery deferreds. Here I have a simple example.
Can anybody tell me why the done function ("now it's my time") is fired before the other functions is done?
The guys in this example also create a deferred object and return a promise, so do I.
How must I change my little example to get the done function only fired after this 6 seconds (after the timeout)?
Thanks alot in advance
Wolfgang
Upvotes: 2
Views: 153
Reputation: 262939
You should pass a function to the done() method, but instead you're calling console.log()
immediately and passing its return value to done()
. You should write:
$.when(test()).done(function() {
console.log("now it's my time");
});
Instead of:
$.when(test()).done(console.log("now it's my time"));
You will find an updated fiddle here.
Upvotes: 6