[英]What is the best way to limit concurrency when using ES6's Promise.all()?
[英]What is the easiest way to wrap Promise in ES6?
我正在使用基于承诺的程序包(Axios)进行HTTP请求。 所以,我有这样的代码:
axios.all(/*many generated requests*/).then((res) => {
//success handler
}).catch((err) => {
//error handler
});
我想编写一个简单的包装器,该包装器会生成并发送所有请求,但仍具有相同的语法。 它将使上面的代码如下所示:
manyReqsWrapper(args).then((res) => {
//success handler
}).catch((err) => {
//error handler
});
我怎样才能做到这一点?
Promise是简单的值,可以像其他所有函数一样从函数中return
。 您似乎在寻找
function mayReqsWrapper(args) {
return axios.all(/* whatever you need */);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.