mirror of
https://github.com/S2-/gitlit
synced 2025-08-04 05:10:05 +02:00
packager
This commit is contained in:
42
app/node_modules/p-limit/index.js
generated
vendored
Normal file
42
app/node_modules/p-limit/index.js
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
'use strict';
|
||||
const pTry = require('p-try');
|
||||
|
||||
module.exports = concurrency => {
|
||||
if (concurrency < 1) {
|
||||
throw new TypeError('Expected `concurrency` to be a number from 1 and up');
|
||||
}
|
||||
|
||||
const queue = [];
|
||||
let activeCount = 0;
|
||||
|
||||
const next = () => {
|
||||
activeCount--;
|
||||
|
||||
if (queue.length > 0) {
|
||||
queue.shift()();
|
||||
}
|
||||
};
|
||||
|
||||
return fn => new Promise((resolve, reject) => {
|
||||
const run = () => {
|
||||
activeCount++;
|
||||
|
||||
pTry(() => fn()).then(
|
||||
val => {
|
||||
resolve(val);
|
||||
next();
|
||||
},
|
||||
err => {
|
||||
reject(err);
|
||||
next();
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
if (activeCount < concurrency) {
|
||||
run();
|
||||
} else {
|
||||
queue.push(run);
|
||||
}
|
||||
});
|
||||
};
|
Reference in New Issue
Block a user