Created
January 20, 2015 15:56
-
-
Save storybynumbers/953ce9fb3a89c0b5d962 to your computer and use it in GitHub Desktop.
A promise-returning function called with parameters using Q.then(), chained sequentially
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 ani = function(d) { | |
var deferred = Q.defer(); | |
setTimeout(function() { | |
console.log('this delayed by ' + d); | |
deferred.resolve(); | |
}, d); | |
return deferred.promise; | |
} | |
ani(1000).then( | |
function() { | |
return ani(1001); | |
}) | |
.then( | |
function() { | |
return ani(1002); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment