Skip to content

Instantly share code, notes, and snippets.

@nmoliveira
Last active August 29, 2015 14:02
Show Gist options
  • Save nmoliveira/2e9a92e4495242357092 to your computer and use it in GitHub Desktop.
Save nmoliveira/2e9a92e4495242357092 to your computer and use it in GitHub Desktop.
Chaining functions with jQuery Deferred
firstTest().then(secondTest).then(thirdTest).then(fourthTest);
function firstTest() {
var def = new $.Deferred();
console.log('First test started');
setTimeout(function () {
console.log('First test finished');
def.resolve();
}, 1000);
return def;
}
function secondTest() {
var def = new $.Deferred();
console.log('Second test started');
setTimeout(function () {
console.log('Second test finished');
def.resolve();
}, 1000);
return def;
}
function thirdTest() {
var def = new $.Deferred();
console.log('Third test started');
setTimeout(function () {
console.log('Third test finished');
def.resolve();
}, 1000);
return def;
}
function fourthTest() {
var def = new $.Deferred();
console.log('Fourth test started');
setTimeout(function () {
console.log('Fourth test finished');
def.resolve();
}, 1000);
return def;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment