Created
March 29, 2017 13:36
-
-
Save Eli-Goldberg/2c0b0383b21983d659ae3501a434e45f to your computer and use it in GitHub Desktop.
Chaining thenables
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
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