Merge remote-tracking branch 'origin/develop' into develop

pull/21833/head
Weblate 2018-05-02 09:45:18 +00:00
commit 023f96e817
1 changed files with 16 additions and 17 deletions

View File

@ -48,25 +48,24 @@ function checkBacklog() {
// Limit the maximum number of ongoing promises returned by fn to LIMIT and
// use a FIFO queue to handle the backlog.
function limitConcurrency(fn) {
return new Promise((resolve, reject) => {
const item = () => {
ongoingRequestCount++;
resolve();
};
async function limitConcurrency(fn) {
if (ongoingRequestCount >= LIMIT) {
// Enqueue this request for later execution
backlogQueue.push(item);
} else {
item();
await new Promise((resolve, reject) => {
backlogQueue.push(resolve);
});
}
})
.then(fn)
.then((result) => {
ongoingRequestCount++;
try {
return await fn();
} catch (err) {
// We explicitly do not handle the error here, but let it propogate.
throw err;
} finally {
ongoingRequestCount--;
checkBacklog();
return result;
});
}
}
/**