Fix semaphore implementation for only doing 10 concurrent fetches at a time
This commit is contained in:
parent
2980ba8565
commit
964e158a5f
@ -49,6 +49,7 @@ class Backend {
|
||||
|
||||
entries(collection, page, perPage) {
|
||||
return this.implementation.entries(collection, page, perPage).then((response) => {
|
||||
console.log("Got %s entries", response.entries.length);
|
||||
return {
|
||||
pagination: response.pagination,
|
||||
entries: response.entries.map(this.entryWithFormat(collection))
|
||||
|
@ -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) => ({
|
||||
|
@ -33,12 +33,15 @@ export default class NetlifyGit {
|
||||
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) => ({
|
||||
|
Loading…
x
Reference in New Issue
Block a user