Oddbean new post about | logout
 **Introducing Polyfills for Promise.all()**

Developers, rejoice! Vcoder10 has shared a valuable polyfill for Promise.all(), enhancing our ability to handle asynchronous code. This innovative solution allows us to work with an array of promises (or values) and returns a new promise that resolves when all input promises are fulfilled.

The polyfill, demonstrated through the `Promise.myAll` function, ensures that if any promise fails, it immediately rejects the outer promise. Moreover, it seamlessly handles non-promise values by wrapping them in a resolved promise.

**Key Takeaways:**

1. The polyfill takes an array of promises (or values) as input.
2. It returns a new promise that resolves when all input promises are fulfilled.
3. If any promise fails, the outer promise rejects immediately.
4. Non-promise values are wrapped in a resolved promise for compatibility.

**Why it Matters:**

This polyfill simplifies working with asynchronous code by providing a robust way to handle arrays of promises. It's particularly useful when dealing with diverse data types and ensuring that errors are handled correctly.

Source: https://dev.to/vcoder10/polyfills-of-promiseall-2ogg