mirror of
https://git.stamm.me/OpenServer/NodeLogging.git
synced 2024-11-14 17:31:05 +00:00
Modify debounce
This commit is contained in:
parent
d39e13dfe1
commit
ca8dffecff
@ -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",
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user