first commit
This commit is contained in:
commit
eb2f504652
32490 changed files with 5731109 additions and 0 deletions
33
node_modules/enquirer/lib/queue.js
generated
vendored
Normal file
33
node_modules/enquirer/lib/queue.js
generated
vendored
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
'use strict';
|
||||
|
||||
module.exports = class Queue {
|
||||
_queue = [];
|
||||
_executing = false;
|
||||
_jobRunner = null;
|
||||
|
||||
constructor(jobRunner) {
|
||||
this._jobRunner = jobRunner;
|
||||
}
|
||||
|
||||
enqueue = (...args) => {
|
||||
this._queue.push(args);
|
||||
this._dequeue();
|
||||
};
|
||||
|
||||
destroy() {
|
||||
this._queue.length = 0;
|
||||
this._jobRunner = null;
|
||||
}
|
||||
|
||||
_dequeue() {
|
||||
if (this._executing || !this._queue.length) return;
|
||||
this._executing = true;
|
||||
|
||||
this._jobRunner(...this._queue.shift());
|
||||
|
||||
setTimeout(() => {
|
||||
this._executing = false;
|
||||
this._dequeue();
|
||||
});
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue