Last active
February 20, 2019 02:50
-
-
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)
This file contains hidden or 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
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); | |
}) | |
; |
Author
darkcolonist
commented
Feb 20, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment