Commit b5a74d22 authored by Mathias Chouet's avatar Mathias Chouet :spaghetti:
Browse files

Progress notifications: every 30ms only

Showing with 14 additions and 2 deletions
+14 -2
...@@ -49,6 +49,9 @@ export abstract class Nub extends ComputeNode implements IObservable { ...@@ -49,6 +49,9 @@ export abstract class Nub extends ComputeNode implements IObservable {
/** a rough indication of calculation progress, between 0 and 100 */ /** a rough indication of calculation progress, between 0 and 100 */
private _progress: number = 0; private _progress: number = 0;
/** allows notifying of progress every X milliseconds only */
private previousNotificationTimestamp = 0;
public constructor(prms: ParamsEquation, dbg: boolean = false) { public constructor(prms: ParamsEquation, dbg: boolean = false) {
super(prms, dbg); super(prms, dbg);
this._children = []; this._children = [];
...@@ -93,11 +96,20 @@ export abstract class Nub extends ComputeNode implements IObservable { ...@@ -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) { protected set progress(v: number) {
this._progress = v; 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() { public get calcType() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment