mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-08-31 15:19:42 +02:00
Fix:Include Watcher as lib with no dependencies and fix tiny-readdir bug #610
This commit is contained in:
parent
160dac109d
commit
ec6e70725c
34 changed files with 2187 additions and 281 deletions
35
server/libs/watcher/atomically/utils/scheduler.js
Normal file
35
server/libs/watcher/atomically/utils/scheduler.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
"use strict";
|
||||
/* IMPORT */
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
/* VARIABLES */
|
||||
const Queues = {};
|
||||
/* SCHEDULER */
|
||||
//TODO: Maybe publish this as a standalone package
|
||||
const Scheduler = {
|
||||
next: (id) => {
|
||||
const queue = Queues[id];
|
||||
if (!queue)
|
||||
return;
|
||||
queue.shift();
|
||||
const job = queue[0];
|
||||
if (job) {
|
||||
job(() => Scheduler.next(id));
|
||||
}
|
||||
else {
|
||||
delete Queues[id];
|
||||
}
|
||||
},
|
||||
schedule: (id) => {
|
||||
return new Promise(resolve => {
|
||||
let queue = Queues[id];
|
||||
if (!queue)
|
||||
queue = Queues[id] = [];
|
||||
queue.push(resolve);
|
||||
if (queue.length > 1)
|
||||
return;
|
||||
resolve(() => Scheduler.next(id));
|
||||
});
|
||||
}
|
||||
};
|
||||
/* EXPORT */
|
||||
exports.default = Scheduler;
|
Loading…
Add table
Add a link
Reference in a new issue