Skip to content

Instantly share code, notes, and snippets.

@renatoeufe
Created September 13, 2013 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renatoeufe/6547266 to your computer and use it in GitHub Desktop.
Save renatoeufe/6547266 to your computer and use it in GitHub Desktop.
deferred
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