Skip to content

Instantly share code, notes, and snippets.

@JoshM1994
Created November 8, 2018 04:37
Show Gist options
  • Save JoshM1994/c953e991a82725ca71390ef072d6f90e to your computer and use it in GitHub Desktop.
Save JoshM1994/c953e991a82725ca71390ef072d6f90e to your computer and use it in GitHub Desktop.
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