function foo() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("foo")
}, 100)
})
}
function bar() {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve("bar")
}, 200)
})
}
// Instead of doing:
// foo().then(a => {
// bar().then(b => {
// console.log(a)
// console.log(b)
// })
// })
// do this instead:
Promise.all([foo(), bar()]).then(([a, b]) => {
console.log(a)
console.log(b)
})
To embed this program on your website, copy the following code and paste it into your website's HTML: