Skip to content

Instantly share code, notes, and snippets.

@tomgullo
Created June 6, 2013 14:17
Show Gist options
  • Save tomgullo/5721848 to your computer and use it in GitHub Desktop.
Save tomgullo/5721848 to your computer and use it in GitHub Desktop.
q promise example
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