I noticed an example of concurrent promises from MDN:
async function foo() {
const p1 = new Promise((resolve) => setTimeout(() => resolve('1'), 1000))
const p2 = new Promise((_,reject) => setTimeout(() => reject('2'), 500))
const results = [await p1, await p2];
}
foo().catch(() => {}) // Attempt to swallow all errors...
MDN states:
in the following code an unhandled promise rejection error will be thrown, even if a .catch handler has been configured further along the promise chain. This is because p2 will not be "wired into" the promise chain until control returns from p1.
What exactly does this mean? If await waits for p1's promise to resolve first, why then does the rejection error occur for p2? I am very new to asynchronous function and am grateful for any new insights!