wsyq1n
wsyq1n

Reputation: 117

Axios deprecated concurrent requests?

Currently the axios readme says this unhelpfully formatted section:

Concurrency (Deprecated)

Please use Promise.all to replace the below functions.

Helper functions for dealing with concurrent requests.

axios.all(iterable) axios.spread(callback)

So is .all and .spread deprecated or is the use of Promise.all to replace the other methods deprecated? Is concurrency itself deprecated? What's the recommended method of concurrent request handling?

Upvotes: 2

Views: 3128

Answers (1)

Luke Storry
Luke Storry

Reputation: 6722

As it says, they have deprecated their own axios.all(iterable) and axios.spread(callback) functions, instead recommending you use JS's new in-built Promise.all(iterable) function, which does almost the same thing: takes an iterable of promises as an input, and returns a single Promise that resolves to an array of the results of the input promises.

The concurrency example in the README is as follows:

function getUserAccount() {
  return axios.get('/user/12345');
}

function getUserPermissions() {
  return axios.get('/user/12345/permissions');
}

Promise.all([getUserAccount(), getUserPermissions()])
  .then(function (results) {
    const acct = results[0];
    const perm = results[1];
  });

Upvotes: 6

Related Questions