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