Read 09: Cache Invalidation - corey-marchand/data-structures-and-algorithms GitHub Wiki

--5 static methods in the Promise class--

  • promise.all: takes an array of promises (technically can be any iterable, but usually an array) and returns a new promise. The new promise resolves when all listed promises are settled and the array of their results becomes its result. For instance, the Promise.all below settles after 3 seconds, and then its result is an array [1, 2, 3]:

  • promise.allSettled- waits for all promises to settle. The resulting array has:

    {status:"fulfilled", value:result} for successful responses, {status:"rejected", reason:error} for errors.

    For example, we’d like to fetch the information about multiple users. Even if one request fails, we’re still interested in the others.

  • promise.race - waits only for the first settled promise, and gets its result (or error).

---Summary---

There are 5 static methods of Promise class:

* Promise.all(promises) – waits for all promises to resolve and returns an array of their results. If any of                        the given promises rejects, then it becomes the error of Promise.all, and all other results are ignored.
* Promise.allSettled(promises) (recently added method) – waits for all promises to settle and returns their results as array of objects with:
    state: "fulfilled" or "rejected"
    value (if fulfilled) or reason (if rejected).
*  Promise.race(promises) – waits for the first promise to settle, and its result/error becomes the outcome.
* Promise.resolve(value) – makes a resolved promise with the given value.
*  Promise.reject(error) – makes a rejected promise with the given error.

Of these five, Promise.all is probably the most common in practice.