JavaScript Promise.all() Method

Hello friends, today we will see the Promise.all() method one of a javascript function to handle the multiple promises requests.

JavaScript promise object based on two code points, the one is producing code and another is consuming code. When producing code returns the result then it should have to call the two callback functions success() and error().

Note: Producing code is that which will take some time to run and consuming code is that which has to wait for the result.

Let’s see how we can use the Promise.all() method in javascript.

JavaScript Promise.all() Method

The Promise.all() method is used to iterable promises and it returns a single Promise that is the result of other Promises.

You can use Promise.all() method when you want to run multiple promises and wait for them all to be resolved successfully and returns an array of results of the input promises.

Please note that if one of the promises fails, the whole operation will be rejected. See the following example code to understand.

The above code will run all promises greeting, user, and interest together and wait for the result array and then print them.

Leave a Reply

Your email address will not be published.