shelving 1.68.5 → 1.69.0

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/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.68.5",
14
+ "version": "1.69.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -18,7 +18,10 @@ export class SelfClosingState extends State {
18
18
  export class DelayedSelfClosingState extends State {
19
19
  constructor(delay, ...args) {
20
20
  super(...args);
21
- this._timeout = new Timeout(delay);
21
+ this._timeout = new Timeout(() => {
22
+ if (!this.closed)
23
+ this.complete();
24
+ }, delay);
22
25
  }
23
26
  // Override to clear the timeout when an observer is added.
24
27
  _addFirstObserver() {
@@ -26,9 +29,6 @@ export class DelayedSelfClosingState extends State {
26
29
  }
27
30
  // Override to close this state when the last observer is removed.
28
31
  _removeLastObserver() {
29
- this._timeout.set(() => {
30
- if (!this.closed)
31
- this.complete();
32
- });
32
+ this._timeout.set();
33
33
  }
34
34
  }
package/util/async.js CHANGED
@@ -69,7 +69,7 @@ export async function callAsyncParallel(callback, items, ...args) {
69
69
  // Internal way for us to save `resolve()` and `reject()` from a new Promise used by `Deferred` and `ExtendablePromise`
70
70
  let resolve; // eslint-disable-line @typescript-eslint/no-explicit-any
71
71
  let reject;
72
- function saveResolveReject(x, // eslint-disable-line @typescript-eslint/no-explicit-any
72
+ function _saveResolveReject(x, // eslint-disable-line @typescript-eslint/no-explicit-any
73
73
  y) {
74
74
  resolve = x;
75
75
  reject = y;
@@ -77,7 +77,7 @@ y) {
77
77
  /** Type of `Promise` with its `resolve()` and `reject()` methods exposed publicly. */
78
78
  export class Deferred extends Promise {
79
79
  constructor() {
80
- super(saveResolveReject);
80
+ super(_saveResolveReject);
81
81
  this.resolve = resolve;
82
82
  this.reject = reject;
83
83
  }
@@ -90,7 +90,7 @@ export class Deferred extends Promise {
90
90
  /** Type of `Promise` with `._resolve()` and `._reject()` methods available. */
91
91
  export class AbstractPromise extends Promise {
92
92
  constructor() {
93
- super(saveResolveReject);
93
+ super(_saveResolveReject);
94
94
  this._resolve = resolve;
95
95
  this._reject = reject;
96
96
  }
package/util/timeout.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { Dispatch } from "./function.js";
1
2
  /**
2
3
  * Create a new Timeout.
3
4
  *
@@ -9,9 +10,10 @@
9
10
  * @param ms The default delay for any created timeouts (in ms).
10
11
  */
11
12
  export declare class Timeout {
13
+ private _callback;
12
14
  private _ms;
13
15
  private _timeout;
14
- constructor(ms?: number);
16
+ constructor(callback?: Dispatch | null, ms?: number);
15
17
  /** Is a timeout currently set? */
16
18
  get exists(): boolean;
17
19
  /**
@@ -19,7 +21,8 @@ export declare class Timeout {
19
21
  * @param callback
20
22
  * @param ms The delay for this timeout (in ms).
21
23
  */
22
- set(callback: () => void, ms?: number): void;
24
+ set(callback?: Dispatch | null, ms?: number): void;
25
+ private _run;
23
26
  /** Cancel any existing timeout.. */
24
27
  clear(): void;
25
28
  }
package/util/timeout.js CHANGED
@@ -9,8 +9,14 @@
9
9
  * @param ms The default delay for any created timeouts (in ms).
10
10
  */
11
11
  export class Timeout {
12
- constructor(ms = 0) {
13
- this._timeout = undefined;
12
+ constructor(callback = null, ms = 0) {
13
+ this._timeout = null;
14
+ this._run = () => {
15
+ this._timeout = null;
16
+ if (this._callback)
17
+ this._callback();
18
+ };
19
+ this._callback = callback;
14
20
  this._ms = ms;
15
21
  }
16
22
  /** Is a timeout currently set? */
@@ -22,16 +28,22 @@ export class Timeout {
22
28
  * @param callback
23
29
  * @param ms The delay for this timeout (in ms).
24
30
  */
25
- set(callback, ms = this._ms) {
31
+ set(callback = this._callback, ms = this._ms) {
26
32
  this.clear();
27
- this._timeout = setTimeout(() => {
28
- this._timeout = undefined;
29
- callback();
30
- }, ms);
33
+ this._timeout = setTimeout(_executeTimeout, ms, this, callback);
31
34
  }
32
35
  /** Cancel any existing timeout.. */
33
36
  clear() {
34
- if (this._timeout)
35
- this._timeout = void clearTimeout(this._timeout);
37
+ const timeout = this._timeout;
38
+ if (timeout) {
39
+ this._timeout = null;
40
+ clearTimeout(timeout);
41
+ }
36
42
  }
37
43
  }
44
+ /** Actually execute the timeout. */
45
+ function _executeTimeout(timeout, callback) {
46
+ timeout.clear();
47
+ if (callback)
48
+ callback();
49
+ }