Created
November 8, 2018 04:30
-
-
Save JoshM1994/0527fd238001b56e2e27b907173c3785 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 waitPromiseAll() { | |
const startTime = new Date().getTime(); | |
let obj = {}; | |
let promises = []; | |
promises.push(obj["a"] = await promiseWait(100, startTime)) | |
promises.push(obj["b"] = await promiseWait(100, startTime)) | |
await Promise.all(promises) | |
console.log("waitPromiseAll", obj) | |
} | |
// waitPromiseAll { a: 105, b: 210 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment