Home:ALL Converter>Is there a way to get values of only resolved promises?

Is there a way to get values of only resolved promises?

Ask Time:2022-03-26T11:42:26         Author:Hema latha R

Json Formatter

I'm calling multiple services which includes network calls and other asynchronous services in my JavaScript application.

At first I was invoking these promises one by one. In the long run it's getting hard to maintain since I'm invoking more services.

I read somewhere in the internet that we can use Promise.all() to group all promises and execute everything at a time.

The issue is, if any one of the promise is getting rejected all other promises are also getting rejected, this is not what I need.

I'm working in a status dashboard where I need to ping multiple services and show whether the service is up or not. By using Promise.all, it's not working in a way I wished.

Tried another method Promise.any(), but it just resolves when any one is resolved.

Took a look at MDN docs, there are many functions for promise it's overwhelming to me because I'm a beginner in JavaScript.

Currently I've created a very own service which takes care of calling all the promises and counts with the response. Is there any cleaner way to do it?

Author:Hema latha R,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/71625149/is-there-a-way-to-get-values-of-only-resolved-promises
yy