axios-extra
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -97,2 +97,7 @@ const Queue = require('promise-queue-plus/create')(Promise); | ||
} | ||
if (property === "requestQueue") { | ||
// const { start, stop, clear } = queue; | ||
// return { start, stop, clear }; | ||
return queue; | ||
} | ||
return attr; | ||
@@ -99,0 +104,0 @@ } |
{ | ||
"name": "axios-extra", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Extend \"Axios\"; add concurrency limits, retry, etc.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,2 +28,4 @@ # axios-extra | ||
}); | ||
let {stop, start, clear} = axios1.requestQueue; // 暴露内部的队列对像,可以使用 stop start clear 等 API; | ||
``` | ||
@@ -52,2 +54,2 @@ | ||
const axios = aec(requeir('axios'), 5, { retry: 5 }); | ||
``` | ||
``` |
@@ -1,5 +0,6 @@ | ||
import test from 'ava'; | ||
import axios from '../index'; | ||
import test from "ava"; | ||
import axios from "../index"; | ||
const testUrl = "https://www.baidu.com"; | ||
test('maxConcurrent 不能小于等于零', t => { | ||
test("maxConcurrent 不能小于等于零", (t) => { | ||
t.plan(4); | ||
@@ -9,15 +10,80 @@ t.throws(() => { | ||
}); | ||
t.throws(function(){ | ||
t.throws(function () { | ||
let axios1 = axios.create({ | ||
maxConcurrent: 0 | ||
maxConcurrent: 0, | ||
}); | ||
}) | ||
}); | ||
t.throws(() => { | ||
axios.defaults.maxConcurrent = -1; | ||
}); | ||
t.throws(function(){ | ||
t.throws(function () { | ||
let axios1 = axios.create({ | ||
maxConcurrent: -1 | ||
maxConcurrent: -1, | ||
}); | ||
}) | ||
}); | ||
}); | ||
test("调用Queue API stop", async (t) => { | ||
t.plan(1); | ||
const axios1 = axios.create({ maxConcurrent: 1 }); | ||
let k = Promise.all([ | ||
axios1.get(testUrl).then(t.pass, t.fail) | ||
]); | ||
axios1.get(testUrl).then(t.fail, t.fail); | ||
axios1.get(testUrl).then(t.fail, t.fail); | ||
axios1.get(testUrl).then(t.fail, t.fail); | ||
axios1.requestQueue.stop(); | ||
return k; | ||
}); | ||
test("调用Queue API start", async (t) => { | ||
t.plan(4); | ||
const axios1 = axios.create({ maxConcurrent: 1 }); | ||
let k = Promise.all([ | ||
axios1.get(testUrl).then(t.pass, t.fail), | ||
axios1.get(testUrl).then(t.pass, t.fail), | ||
axios1.get(testUrl).then(t.pass, t.fail), | ||
axios1.get(testUrl).then(t.pass, t.fail), | ||
]); | ||
axios1.requestQueue.stop(); | ||
setTimeout(() => { | ||
axios1.requestQueue.start(); | ||
}, 100) | ||
return k; | ||
}); | ||
test("调用Queue API clear", async (t) => { | ||
t.plan(4); | ||
const axios1 = axios.create({ maxConcurrent: 1 }); | ||
let k = Promise.all([ | ||
axios1.get(testUrl).then( | ||
(data) => { | ||
t.pass(); | ||
}, | ||
(err) => { | ||
t.fail(); | ||
} | ||
), | ||
axios1.get(testUrl).then( | ||
t.fail, | ||
(err) => { | ||
t.is(err, "runClear"); | ||
} | ||
), | ||
axios1.get(testUrl).then( | ||
t.fail, | ||
(err) => { | ||
t.is(err, "runClear"); | ||
} | ||
), | ||
axios1.get(testUrl).then( | ||
t.fail, | ||
(err) => { | ||
t.is(err, "runClear"); | ||
} | ||
), | ||
]); | ||
axios1.requestQueue.clear('runClear'); | ||
return k; | ||
}); |
module.exports = function teset(test, axios, defConcurrent = 10, defRetry = 0) { | ||
const testUrl = 'https://cnodejs.org/api/v1/topics'; | ||
const testUrl = 'https://www.baidu.com'; | ||
function test_retry(retry){ | ||
@@ -26,3 +26,3 @@ return (t)=>{ | ||
// console.log(1); | ||
t.is(data.success, true); | ||
t.pass() | ||
}); | ||
@@ -29,0 +29,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
12656
297
53