Created
September 13, 2013 06:26
-
-
Save renatoeufe/6547266 to your computer and use it in GitHub Desktop.
deferred
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var FunctionOne = function () { | |
var | |
a = $.Deferred(), | |
b = $.Deferred(); | |
// some fake asyc task | |
setTimeout(function () { | |
console.log('a done'); | |
a.resolve(); | |
}, Math.random() * 4000); | |
// some other fake asyc task | |
setTimeout(function () { | |
console.log('b done'); | |
b.resolve(); | |
}, Math.random() * 4000); | |
return $.Deferred(function (def) { | |
$.when(a, b).done(function () { | |
def.resolve(); | |
}); | |
}); | |
}; | |
var FunctionTwo = function () { | |
console.log('FunctionTwo'); | |
}; | |
FunctionOne().done(FunctionTwo); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment