Promise.all()

  • Promise.all() is a method that combines all the user-defined promises and returns a single promise in the form of an array in which the result is the sequential combination of all the promises.
  • If any user doesn’t wish to print the output in the form of an array, then that user may run any loop or method over an array and print the values in the console (Promise.all() returns an iterable object which is an array itself.).
  • One thing that is associated with the Promise.all() is that, if one of the promises is returning the output as rejected, it wouldn’t be giving the output of the other successfully executed promises.

Syntax:

Promise.all([ first_promise , second_promise, .......])

Example: Following is the pseudo-code which will help you to understand more about Promise.all().

let promise1 = new Promise(()=> resolve(10));
let promise2 = new Promise(()=> resolve(20));
let final_promise = Promise.all([promise1, promise2]);

Explain Promise.all with async-await in JavaScript

In this article, we will try to understand how we could use Promise.all() along with the async-await using certain predefined syntax with ease in JavaScript. Before we directly jump into our defined task, let us first understand quickly in brief the basics associated with the Promise.all() and async-await.

Similar Reads

Promise.all()

Promise.all() is a method that combines all the user-defined promises and returns a single promise in the form of an array in which the result is the sequential combination of all the promises. If any user doesn’t wish to print the output in the form of an array, then that user may run any loop or method over an array and print the values in the console (Promise.all() returns an iterable object which is an array itself.). One thing that is associated with the Promise.all() is that, if one of the promises is returning the output as rejected, it wouldn’t be giving the output of the other successfully executed promises....

Async-await

Async-await are the two keywords that we use to illustrate a particular function or method as an asynchronous data acceptor. Using async-await keywords we may easily show and capture the asynchronous, promise-based behavior in a very much cleaner style....

Contact Us