diff --git a/package.json b/package.json index 4e05ce3..af1a6b2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hibas123/nodelogging", - "version": "3.0.6", + "version": "3.0.9", "description": "", "main": "out/index.js", "types": "out/index.d.ts", diff --git a/src/filewriter.ts b/src/filewriter.ts index e24f2f0..b5c5426 100644 --- a/src/filewriter.ts +++ b/src/filewriter.ts @@ -33,14 +33,24 @@ export class LoggingFiles implements Adapter { //TODO: Optimise write path -const Debounce = (callback: () => void, iv = 500) => { +const Debounce = (callback: () => void, iv = 500, max = 100) => { let to: any; + let curr = 0; return { trigger: () => { - if (!to) { + curr++; + if (curr >= max) { + if (to) { + clearTimeout(to); + to = undefined; + } + curr = 0; + callback(); + } else if (!to) { to = setTimeout(() => { to = undefined; + curr = 0; callback(); }, iv); } @@ -67,7 +77,7 @@ export class Files { private size: number = 0; private stream: fs.WriteStream = undefined; private lock = new Lock(); - private debounce = Debounce(() => this.checkQueue); + private debounce = Debounce(this.checkQueue.bind(this)); #initialized = false;