async function foo(x) {
console.log("foo", x)
}
async function bar(x) {
throw new Error("bar" + x)
}
class DeferredPromiseExecutor {
constructor() {
this.calls = []
}
add(func, ...args) {
this.calls.push([func, args])
}
run() {
return Promise.all(this.calls.map(x => x[0](...x[1])))
}
}
async function foobar() {
const dp = new DeferredPromiseExecutor()
dp.add(foo, 10)
dp.add(bar, 40)
try {
await dp.run()
} catch (e) {
console.log("caught exception: " + e)
}
}
foobar()
To embed this program on your website, copy the following code and paste it into your website's HTML: