First release
This commit is contained in:
commit
fa6c85266e
2339 changed files with 761050 additions and 0 deletions
31
node_modules/throttles/priority/index.js
generated
vendored
Normal file
31
node_modules/throttles/priority/index.js
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
module.exports = function (limit) {
|
||||
limit = limit || 1;
|
||||
var qlow=[], idx, qhigh=[], sum=0, wip=0;
|
||||
|
||||
function toAdd(fn, isHigh) {
|
||||
if (fn.__t) {
|
||||
if (isHigh) {
|
||||
idx = qlow.indexOf(fn);
|
||||
// must decrement (increments again)
|
||||
if (!!~idx) qlow.splice(idx, 1).length && sum--;
|
||||
} else return;
|
||||
}
|
||||
fn.__t = 1;
|
||||
(isHigh ? qhigh : qlow).push(fn);
|
||||
sum++ || run(); // initializes if 1st
|
||||
}
|
||||
|
||||
function isDone() {
|
||||
wip--; // make room for next
|
||||
run();
|
||||
}
|
||||
|
||||
function run() {
|
||||
if (wip < limit && sum > 0) {
|
||||
(qhigh.shift() || qlow.shift())();
|
||||
sum--; wip++; // is now WIP
|
||||
}
|
||||
}
|
||||
|
||||
return [toAdd, isDone];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue