Created
November 8, 2018 04:37
-
-
Save JoshM1994/c953e991a82725ca71390ef072d6f90e 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
function promiseWait(timeToWait, startTime) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => { | |
resolve(new Date().getTime() - startTime); | |
}, timeToWait); | |
}); | |
} | |
async function waitChainPromiseAll() { | |
const startTime = new Date().getTime(); | |
let obj = {}; | |
let promises = []; | |
promises.push(promiseWait(100, startTime).then(res => obj["a"] = res)) | |
promises.push(promiseWait(100, startTime).then(res => obj["b"] = res)) | |
await Promise.all(promises) | |
console.log("waitChainPromiseAll", obj) | |
} | |
// waitChainPromiseAll { a: 105, b: 105 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment