@fbltd/async 1.0.38 → 1.0.39

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.
@@ -1,7 +1,7 @@
1
1
  import { PromiseConfiguration } from "../promise-configuration.js";
2
2
  import { baseComparer } from "./utils.js";
3
- import { observationState } from "./observe.state.js";
4
3
  import { symAI } from "../constants.js";
4
+ import { observationState } from "./observe.state.js";
5
5
  export class Dependency {
6
6
  _value;
7
7
  reactionPromise;
@@ -38,7 +38,7 @@ export class Dependency {
38
38
  return this._value;
39
39
  }
40
40
  get done() {
41
- return this.abortPromise.isFulfilled;
41
+ return !this.abortPromise || this.abortPromise.isFulfilled;
42
42
  }
43
43
  [symAI](thisStreamConfig = {}) {
44
44
  const externalPromises = [];
@@ -50,20 +50,18 @@ export class Dependency {
50
50
  externalPromises.push(firstPromise.promise);
51
51
  }
52
52
  const owner = this;
53
- let done = false;
54
53
  return {
55
54
  owner,
56
- dispose: owner.dispose.bind(owner),
55
+ dispose: () => { },
57
56
  get isDisposed() {
58
- return done || owner.done;
57
+ return false;
59
58
  },
60
59
  next: async () => {
61
60
  await Promise.race([
62
- ...externalPromises,
63
61
  owner.next(),
62
+ ...externalPromises,
64
63
  ]);
65
64
  if (this.done) {
66
- done = true;
67
65
  return { done: true };
68
66
  }
69
67
  if (firstPromise) {
@@ -98,23 +96,24 @@ export class Dependency {
98
96
  * Another subscribe for current race
99
97
  */
100
98
  async next() {
99
+ const done = { done: true };
100
+ const owner = this;
101
+ if (this.done)
102
+ return done;
101
103
  await this.getOrCreateRace();
102
104
  this._race = undefined;
103
- if (this.done) {
104
- return { done: true };
105
- }
105
+ if (this.done)
106
+ return done;
107
+ this.abortPromise = new PromiseConfiguration();
106
108
  return {
107
109
  done: false,
108
110
  get value() {
109
- return this.value;
111
+ return owner.value;
110
112
  }
111
113
  };
112
114
  }
113
- get disposePromise() {
114
- return this.abortPromise.promise;
115
- }
116
115
  dispose() {
117
- this.abortPromise.resolve();
118
- this.reactionPromise = undefined;
116
+ this.abortPromise?.resolve();
117
+ this.abortPromise = this.reactionPromise = undefined;
119
118
  }
120
119
  }
@@ -13,7 +13,7 @@ export function reaction(fn, config) {
13
13
  depsArray = Array.from(deps);
14
14
  beforeValues = depsArray.map(dep => dep.value_unsafe);
15
15
  const promises = depsArray.map(dep => dep.next());
16
- promises.push(dep.disposePromise);
16
+ // promises.push(dep.disposePromise as Promise<any>);
17
17
  await Promise.race(depsArray.map(dep => dep.next()));
18
18
  if (dep.done)
19
19
  return { done: true };
@@ -23,11 +23,10 @@ export declare class Dependency<T = any> {
23
23
  */
24
24
  next(): Promise<{
25
25
  done: true;
26
- value?: never;
26
+ value: void;
27
27
  } | {
28
28
  done: boolean;
29
29
  readonly value: T;
30
30
  }>;
31
- get disposePromise(): Promise<void>;
32
31
  dispose(this: Dependency<T>): void;
33
32
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/async",
3
- "version": "1.0.38",
3
+ "version": "1.0.39",
4
4
  "description": "Miscellaneous async utils",
5
5
  "homepage": "https://github.com/GlennMiller1991/async",
6
6
  "type": "module",