Skip to content

Instantly share code, notes, and snippets.

@joao-pedrozo
Last active June 22, 2022 13:59
Show Gist options
  • Save joao-pedrozo/3dd49dedb154293b1c8f4d1339016b2d to your computer and use it in GitHub Desktop.
Save joao-pedrozo/3dd49dedb154293b1c8f4d1339016b2d to your computer and use it in GitHub Desktop.
Test promises
await Promise.all([
new Promise((resolve) => setTimeout(() => {resolve('A (slow)'); console.log('A (slow)')}, 1000)),
new Promise((resolve) => setTimeout(() => {resolve('B (slower)'); console.log('B (slower)')}, 2000)),
new Promise((resolve) => setTimeout(() => {resolve('C (fast)'); console.log('C (fast)')}, 10))
])
const promises = Array.from({ length: 1000 }, (_, i) => i).map(item => new Promise((resolve) => setTimeout(() => {
resolve('A');
console.log('resolved')
}, 3000)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment