Skip to content

Instantly share code, notes, and snippets.

@storybynumbers
Created January 20, 2015 15:56
Show Gist options
  • Save storybynumbers/953ce9fb3a89c0b5d962 to your computer and use it in GitHub Desktop.
Save storybynumbers/953ce9fb3a89c0b5d962 to your computer and use it in GitHub Desktop.
A promise-returning function called with parameters using Q.then(), chained sequentially
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