dfdf
async function test(urlList) { | |
const promiseList = urlList.map(url => async () => axios.get(url)); | |
return promiseList.reduce((p, fn) => p.then((value) => { | |
console.log('value', value); | |
return delay(2000); | |
}).then(fn), Promise.resolve()); | |
} | |
test(['http://ip.jsontest.com', 'http://headers.jsontest.com', 'http://time.jsontest.com']) | |
.then((value) => { | |
console.log('value last', value.data); | |
}); |
async function test(urlList) { | |
if (urlList.length === 0) { | |
return; | |
} | |
const errorUrlList = []; | |
for (let i = 0; i < urlList.length; i += 1) { | |
const url = urlList[i]; | |
try { | |
const res = Math.random() > 0.5 ? await axios.get(url) : await axios.get(1); | |
console.log(res.data); | |
} catch (e) { | |
errorUrlList.push(url); | |
} finally { | |
await delay(2000); // eslint-disable-line no-await-in-loop | |
} | |
} | |
} | |
test(errorUrlList); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment