@dra2020/baseclient 1.0.7 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fsm/fsm.d.ts CHANGED
@@ -63,6 +63,7 @@ export declare class FsmOnDone extends Fsm {
63
63
  }
64
64
  export declare class FsmSleep extends Fsm {
65
65
  delay: number;
66
+ timeoutHandle: any;
66
67
  constructor(env: FsmEnvironment, delay: number);
67
68
  tick(): void;
68
69
  }
package/lib/fsm/fsm.ts CHANGED
@@ -291,6 +291,7 @@ export class FsmOnDone extends Fsm
291
291
  export class FsmSleep extends Fsm
292
292
  {
293
293
  delay: number;
294
+ timeoutHandle: any;
294
295
 
295
296
  constructor(env: FsmEnvironment, delay: number)
296
297
  {
@@ -300,10 +301,19 @@ export class FsmSleep extends Fsm
300
301
 
301
302
  tick(): void
302
303
  {
303
- if (this.ready && this.state === FSM_STARTING)
304
+ // This allows canceling by simply setting state to done
305
+ if (this.done && this.timeoutHandle !== undefined)
306
+ {
307
+ clearTimeout(this.timeoutHandle);
308
+ delete this.timeoutHandle;
309
+ }
310
+ else if (this.ready && this.state === FSM_STARTING)
304
311
  {
305
312
  this.setState(FSM_PENDING);
306
- setTimeout(() => { this.setState(FSM_DONE); }, this.delay);
313
+ this.timeoutHandle = setTimeout(() => {
314
+ delete this.timeoutHandle;
315
+ this.setState(FSM_DONE)
316
+ }, this.delay);
307
317
  }
308
318
  }
309
319
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",