Fix semaphore implementation for only doing 10 concurrent fetches at a time

This commit is contained in:
Mathias Biilmann Christensen
2016-09-04 20:55:05 +02:00
parent 2980ba8565
commit 964e158a5f
3 changed files with 15 additions and 8 deletions

View File

@ -36,12 +36,15 @@ export default class GitHub {
const sem = semaphore(MAX_CONCURRENT_DOWNLOADS);
const promises = [];
files.map((file) => {
sem.take(() => {
promises.push(this.api.readFile(file.path, file.sha).then((data) => {
promises.push(new Promise((resolve, reject) => {
return sem.take(() => this.api.readFile(file.path, file.sha).then((data) => {
resolve(createEntry(file.path, file.path.split('/').pop().replace(/\.[^\.]+$/, ''), data));
sem.leave();
return createEntry(file.path, file.path.split('/').pop().replace(/\.[^\.]+$/, ''), data);
}).catch((err) => {
sem.leave();
reject(err);
}));
});
}));
});
return Promise.all(promises);
}).then((entries) => ({