From b5a74d22897f71d836faed0bda90c0fe370493ce Mon Sep 17 00:00:00 2001 From: "mathias.chouet" <mathias.chouet@irstea.fr> Date: Fri, 17 May 2019 15:12:29 +0200 Subject: [PATCH] Progress notifications: every 30ms only --- src/nub.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nub.ts b/src/nub.ts index 2cdd6c3e..78a78e0b 100644 --- a/src/nub.ts +++ b/src/nub.ts @@ -49,6 +49,9 @@ export abstract class Nub extends ComputeNode implements IObservable { /** a rough indication of calculation progress, between 0 and 100 */ private _progress: number = 0; + /** allows notifying of progress every X milliseconds only */ + private previousNotificationTimestamp = 0; + public constructor(prms: ParamsEquation, dbg: boolean = false) { super(prms, dbg); this._children = []; @@ -93,11 +96,20 @@ export abstract class Nub extends ComputeNode implements IObservable { } /** - * Updates the progress percentage and notifies observers + * Updates the progress percentage and notifies observers, + * at most once per 300ms */ protected set progress(v: number) { this._progress = v; - this.notifyProgressUpdated(); + const currentTime = new Date().getTime(); + if ( + (currentTime - this.previousNotificationTimestamp) > 30 + || v === 100 + ) { + // console.log(">> notifying !"); + this.notifyProgressUpdated(); + this.previousNotificationTimestamp = currentTime; + } } public get calcType() { -- GitLab