Home > OS >  Promise.all vs Axios.all
Promise.all vs Axios.all

Time:08-10

I would like to ask the difference between "Promise.all" & "Axios.all" for several API requests.
I found that both work well in my code, but it is not easy to find its reason..

Could you please explain ?

CodePudding user response:

The Axios documentation on NPM says that Axios.all() is deprecated and you should use Promise.all() in its place. I do not believe there is any intended difference between the two.

In fact, if you look in the current Axios source, you see this:

// Expose all/spread
axios.all = function all(promises) {
  return Promise.all(promises);
};

So, they are identical.

I presume that Axios.all() existed historically when Axios wanted to be able to run in environments that didn't have full native promise support so they were supplying promise functionality that might now be present.

Since all modern environments contain Promise.all(), Axios.all() is no longer necessary.

  • Related