Skip to content

Instantly share code, notes, and snippets.

@darkcolonist
Last active February 20, 2019 02:50
Show Gist options
  • Save darkcolonist/33ffb243db8be2b1d7f7b4823ec0edc3 to your computer and use it in GitHub Desktop.
Save darkcolonist/33ffb243db8be2b1d7f7b4823ec0edc3 to your computer and use it in GitHub Desktop.
nodejs promise instead of async/await - sequential processes (using node v6.2.2)
console.log("hello world");
var trace = [];
function getListOfUsers(){
// setTimeout(() => {
// return trace.push('the list of users');
// },1000);
return trace.push('the list of users');
}
Promise.resolve()
.then(getListOfUsers) /** first process */
.then(() => {
// setTimeout(() => {
// return trace.push('the list of properties per-user');
// },1000)
return trace.push('the list of properties per-user');
}) /** second process */
.then(() => {
return new Promise((resolve, reject) => {
setTimeout(() => {
trace.push('huge chunk of data');
resolve(true);
},1000);
});
})
.then(() => {
return new Promise((resolve, reject) => {
// option 1
// return sequelize.query("select * from users;");
// option 2
// sequelize.query("select * from users;")
// .then((results) => {
// trace.push(results);
// resolve(results);
// })
resolve([
"jen",
"joseph",
"louie",
]);
});
})
.then((muvcal)=>{
trace.push(muvcal);
console.log(trace);
})
;
@darkcolonist
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment