axios-extra
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,2 @@ | ||
const Queue = require('promise-queue-plus'); | ||
const Queue = require('promise-queue-plus/create')(Promise); | ||
const apis = new Set(['request', 'get', 'delete', 'head', 'options', 'post', 'put', 'patch']); | ||
@@ -9,4 +9,3 @@ const DEF_MAX_CONCURRENT = 10; | ||
let axiosConfig = args[args.length - 1]; | ||
let queueOptions = | ||
typeof axiosConfig == 'object' ? axiosConfig.queueOptions : undefined; | ||
let queueOptions = typeof axiosConfig == 'object' ? axiosConfig.queueOptions : undefined; | ||
debug && console.log('workQueueOptions:', queueOptions); | ||
@@ -33,2 +32,38 @@ if (debug) { | ||
// 为 axios.defaults 添加 maxConcurrent 与 queueOptions 支持 | ||
axios.defaults.queueOptions = queue._options; | ||
Object.defineProperties(axios.defaults, { | ||
maxConcurrent: { | ||
get() { | ||
return queue.getMax(); | ||
}, | ||
set(v) { | ||
queue.setMax(v); | ||
} | ||
}, | ||
queueOptions: { | ||
get() { | ||
return queue._options; | ||
}, | ||
set(v) { | ||
[ | ||
'queueStart', | ||
'queueEnd', | ||
'workAdd', | ||
'workResolve', | ||
'workReject', | ||
'workFinally', | ||
'retry', | ||
'retryIsJump', | ||
'timeout', | ||
'autoRun' | ||
].map(k => { | ||
if (k in v) { | ||
queue._options[k] = k.v; | ||
} | ||
}); | ||
} | ||
} | ||
}); | ||
return new Proxy(axios, { | ||
@@ -57,5 +92,5 @@ apply: function(target, thisArg, argumentsList) { | ||
function create(axios, maxConcurrent = DEF_MAX_CONCURRENT, queueOptions = {}) { | ||
return proxyAxios(new Queue(maxConcurrent, queueOptions), axios); | ||
return proxyAxios(Queue(maxConcurrent, queueOptions), axios); | ||
} | ||
module.exports = create; |
{ | ||
"name": "axios-extra", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Extend \"Axios\"; add concurrency limits, retry, etc.", | ||
@@ -27,4 +27,4 @@ "main": "index.js", | ||
"axios": "^0.18.0", | ||
"promise-queue-plus": "^1.1.0" | ||
"promise-queue-plus": "^1.2.1" | ||
} | ||
} |
@@ -50,5 +50,1 @@ # axios-extra | ||
``` | ||
## 己知问题 | ||
- 不能通过 `axios.defaults` 更改并发及重试次数. |
@@ -5,2 +5,4 @@ const axios = require('../').create({ maxConcurrent: 1 }); | ||
// axios.defaults.maxConcurrent = 3; | ||
for (var i = 0; i < max; i++) { | ||
@@ -7,0 +9,0 @@ +(function(k) { |
@@ -5,2 +5,4 @@ const axios = require('../').create({ maxConcurrent: 1, queueOptions: { retry: 3, retryIsJump: true } }); | ||
axios.defaults.queueOptions.retry = 0; | ||
let x = 0; | ||
@@ -7,0 +9,0 @@ //添加一个拦截器,模拟失败 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7052
155
50
Updatedpromise-queue-plus@^1.2.1