简体   繁体   English

Axios 已弃用并发请求?

[英]Axios deprecated concurrent requests?

Currently the axios readme says this unhelpfully formatted section:目前 axios 自述文件说这个无用的格式化部分:

Concurrency (Deprecated)并发(已弃用)

Please use Promise.all to replace the below functions.请使用 Promise.all 替换以下函数。

Helper functions for dealing with concurrent requests.处理并发请求的辅助函数。

axios.all(iterable) axios.spread(callback) axios.all(可迭代) axios.spread(回调)

So is.all and.spread deprecated or is the use of Promise.all to replace the other methods deprecated?那么是.all 和.spread 已弃用,还是使用 Promise.all 代替其他方法已弃用? Is concurrency itself deprecated?并发本身是否已弃用? What's the recommended method of concurrent request handling?并发请求处理的推荐方法是什么?

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. 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可迭代的承诺作为输入,并返回单个 Promise 解析为输入承诺结果的数组。

The concurrency example in the README is as follows: README中的并发示例如下:

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];
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM