Skip to content

Instantly share code, notes, and snippets.

@velotio-tech
Created May 30, 2017 04:16
Show Gist options
  • Save velotio-tech/1aedf5168efe5a23738bf828010d1233 to your computer and use it in GitHub Desktop.
Save velotio-tech/1aedf5168efe5a23738bf828010d1233 to your computer and use it in GitHub Desktop.
NodeJS Chaining Using Promises
var foo = function (arg) {
return new Promise((resolve, reject) => {
resolve(arg+1);
});
}
var bar = function (arg) {
return new Promise((resolve, reject) => {
resolve(arg+2);
});
}
var baz = function (arg) {
return new Promise((resolve, reject) => {
resolve(arg+3);
});
}
var log = function (arg) {
console.log(arg);
}
foo(0)
.then(bar)
.then(baz)
.then(log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment