tezvyn:

Promise.any(): Get the Fastest Successful Result

Source: developer.mozilla.orgadvanced

Promise.any() is a race where only finishers count. It returns the value of the first promise to succeed, ignoring any that fail. Use it to query redundant endpoints and take the first successful response.

Promise.any() is like a race where only finishers count. It takes an array of promises and returns the value of the very first one to succeed, ignoring any that fail along the way. This is perfect for redundancy, like fetching a resource from multiple servers where you only need the first successful response. The common footgun is confusing it with Promise.race(), which settles with the first promise to finish, whether it succeeds *or* fails. `any()` waits for the first success.

Read the original → developer.mozilla.org

Get five bites like this every day.

Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.

Promise.any(): Get the Fastest Successful Result · Tezvyn