Created
April 1, 2013 02:26
-
-
Save heymatthew/5282912 to your computer and use it in GitHub Desktop.
Testing then statement in the Q framework to assert then() return's a wrapped promise callback.
"Give me a callback for this promise and I'll give you a promise that represents the result of that callback."
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
(function() { | |
q = require('q'); | |
var one,two,three; | |
function asyncOne() { | |
console.log('one called'); | |
var allDone = q.defer(); | |
setTimeout(allDone.resolve, 1000); | |
return allDone.promise; | |
} | |
function asyncTwo() { | |
console.log('two called'); | |
var allDone = q.defer(); | |
setTimeout(allDone.resolve, 1000); | |
return allDone.promise; | |
} | |
function asyncThree() { | |
console.log('three called'); | |
var allDone = q.defer(); | |
setTimeout(allDone.resolve, 1000); | |
return allDone.promise; | |
} | |
console.log("Testing 'then' mimics jQuery's pipe"); | |
var oneDone = asyncOne(); | |
var twoDone = oneDone.then( asyncTwo ); | |
var threeDone = twoDone.then( asyncThree ); | |
oneDone.then( function() { console.log('one is done') } ); | |
twoDone.then( function() { console.log('two is done') } ); | |
threeDone.then( function() { console.log('three is done') } ); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment