Skip to content

Instantly share code, notes, and snippets.

@Eli-Goldberg
Created March 29, 2017 13:36
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 Eli-Goldberg/2c0b0383b21983d659ae3501a434e45f to your computer and use it in GitHub Desktop.
Save Eli-Goldberg/2c0b0383b21983d659ae3501a434e45f to your computer and use it in GitHub Desktop.
Chaining thenables
const q = require('q');
function doSomething(data) {
data.one = 1;
return q(data);
}
function somethingElse(data) {
const deferred = q.defer();
setTimeout(function() {
console.log('Yes, I happened.')
deferred.resolve(data);
}, 1000)
return deferred.promise;
}
function yeahImDone(data) {
return q(data);
}
doSomething().then(somethingElse).then(yeahImDone);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment