Last active
June 17, 2018 22:14
-
-
Save narenaryan/d3eecd8d5ad4db3ae27a93642226cecb to your computer and use it in GitHub Desktop.
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
var message = ""; | |
promise1 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
message += "my"; | |
resolve(message); | |
}, 2000) | |
}) | |
promise2 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
message += " first"; | |
resolve(message); | |
}, 2000) | |
}) | |
promise3 = new Promise((resolve, reject) => { | |
setTimeout(() => { | |
message += " promise"; | |
resolve(message); | |
}, 2000) | |
}) | |
var printResult = (results) => {console.log("Results = ", results, "message = ", message)} | |
function main() { | |
// See the order of promises. Final result will be according to it | |
Promise.all([promise1, promise2, promise3]).then(printResult); | |
Promise.all([promise2, promise1, promise3]).then(printResult); | |
Promise.all([promise3, promise2, promise1]).then(printResult); | |
console.log("\"\"" + message); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment