1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-11-15 02:31:03 +00:00

Modify debounce

This commit is contained in:
Fabian Stamm 2021-05-09 15:14:16 +02:00
parent d39e13dfe1
commit ca8dffecff
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@hibas123/nodelogging", "name": "@hibas123/nodelogging",
"version": "3.0.6", "version": "3.0.9",
"description": "", "description": "",
"main": "out/index.js", "main": "out/index.js",
"types": "out/index.d.ts", "types": "out/index.d.ts",

View File

@ -33,14 +33,24 @@ export class LoggingFiles implements Adapter {
//TODO: Optimise write path //TODO: Optimise write path
const Debounce = (callback: () => void, iv = 500) => { const Debounce = (callback: () => void, iv = 500, max = 100) => {
let to: any; let to: any;
let curr = 0;
return { return {
trigger: () => { trigger: () => {
if (!to) { curr++;
if (curr >= max) {
if (to) {
clearTimeout(to);
to = undefined;
}
curr = 0;
callback();
} else if (!to) {
to = setTimeout(() => { to = setTimeout(() => {
to = undefined; to = undefined;
curr = 0;
callback(); callback();
}, iv); }, iv);
} }
@ -67,7 +77,7 @@ export class Files {
private size: number = 0; private size: number = 0;
private stream: fs.WriteStream = undefined; private stream: fs.WriteStream = undefined;
private lock = new Lock(); private lock = new Lock();
private debounce = Debounce(() => this.checkQueue); private debounce = Debounce(this.checkQueue.bind(this));
#initialized = false; #initialized = false;