JSFiddle - React, Tailwind, and code Playground
by lollero
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.20/lodash.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/async/3.2.0/async.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/url.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.26.1/axios.min.js"></script>
JavaScript
const axiosConfig = {
validateStatus: function (status) {
return status >= 200 && status < 400;
},
};
async.mapLimit(
[
'https://reqres.in/api/users?delay=6',
'https://reqres.in/api/users?delay=10&page=4',
'https://reqres.in/api/users?delay=30&page=3',
'https://reqres.in/api/users?delay=10&page=2',
'https://reqres.in/api/users/23?delay=2',
'https://reqres.in/api/users/21?delay=2',
'https://reqres.in/api/users/22?delay=1',
'https://reqres.in/api/users?delay=30&page=1',
'https://reqres.in/api/users/24?delay=1',
'https://reqres.in/api/users/25?delay=1',
'https://reqres.in/api/users/26?delay=1',
'https://reqres.in/api/users?delay=10&page=5',
'https://reqres.in/api/users/27?delay=1',
'https://reqres.in/api/users/28?delay=1',
'https://reqres.in/api/users/29?delay=1',
],
2,
function(request, stepCallback) {
console.log('request');
const controller = new AbortController();
axiosConfig.signal = controller.signal;
let requestTimer = setTimeout(() => {
controller.abort('Request took too long...');
}, 20000);
axios.get(request, axiosConfig).then(function( response ) {
clearTimeout(requestTimer); // Request succeeded: keep alive
const test = response.data;
console.log('SUCCESS:', request );
stepCallback(null, test);
}).catch(function(e) {
clearTimeout(requestTimer); // Request succeeded: keep alive
console.log('ERROR:', request, e);
stepCallback(null, null);
});
},
function( err, results) {
console.log( 'all finished!' );
console.log( err, results );
}
);