Last active
August 29, 2015 14:02
-
-
Save nmoliveira/2e9a92e4495242357092 to your computer and use it in GitHub Desktop.
Chaining functions with jQuery 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
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