Created
June 6, 2013 14:17
-
-
Save tomgullo/5721848 to your computer and use it in GitHub Desktop.
q promise example
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 addAsync(data) { | |
var d = Q.defer(); | |
setTimeout(function() { | |
console.log('data in ' + data); | |
if (data === 2) { | |
d.reject("rejected!"); | |
} else { | |
d.resolve(data + 1); | |
} | |
}, | |
1000); | |
return d.promise; | |
} | |
var start_with = 1; | |
Q.fcall( | |
addAsync(start_with) | |
.then(addAsync) | |
.then(addAsync) | |
.then( | |
function(result) { console.log("result " + result) }, | |
function(err) { console.log("error " + err) } | |
) | |
); | |
console.log('done'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment