Deviopath › TypeScript

Implement allSettled

Hard · Async

Write your own allSettled(tasks) without using Promise.allSettled. Each task is a function that returns a promise.

- Start ALL tasks right away so they run at the same time (do not wait for one before starting the next).

- The returned promise never rejects. It resolves once every task has finished, with one Settled entry per task IN INPUT ORDER: { status: "fulfilled", value } or { status: "rejected", reason }.

- A task that throws synchronously (instead of returning a rejected promise) also counts as "rejected".

- With no tasks, resolve with [].

The driver runSettled(specs) is already written. It creates tasks from small timers, and also returns the order in which the timers finished.

Next: Retry with Exponential Backoff