Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 32 additions & 7 deletions tfc.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,35 @@ let update = setInterval(() => {
stats.lastTotal = stats.total
}, 5 * 1000)

axios
.all(urls.map(url =>
axios(url, opts)
.then(go)
.catch(err => { stats.total++; return err })
))
.then(axios.spread(done))
const chunk = (array, batchSize = 5) => {
const chunked = [];
for (let i = 0; i < array.length; i += batchSize) {
chunked.push(array.slice(i, i + batchSize))
}

return chunked;
}

const reducer = (chain, batch) => chain
.then(() => Promise.all(
batch.map(url =>
axios(url, opts)
.then(go)
.catch(err => { stats.total++; return err })
)
));

// execute batches of 100 urls in parralel
chunk(urls, 100)
.reduce(
reducer,
Promise.resolve()
).then(done);

// axios
// .all(urls.map(url =>
// axios(url, opts)
// .then(go)
// .catch(err => { stats.total++; return err })
// ))
// .then(axios.spread(done))