[英]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.