@fbltd/async 1.0.35 → 1.0.38
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/bin/dependency/dependency.js +2 -6
- package/dist/bin/dependency/dependency.stream.js +14 -3
- package/dist/bin/dependency/vanilla/race.stream.js +12 -4
- package/dist/bin/index.js +1 -0
- package/dist/types/dependency/contracts.d.ts +0 -6
- package/dist/types/dependency/dependency.stream.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -2
- package/tsconfig.json +0 -4
|
@@ -49,9 +49,6 @@ export class Dependency {
|
|
|
49
49
|
firstPromise.resolve();
|
|
50
50
|
externalPromises.push(firstPromise.promise);
|
|
51
51
|
}
|
|
52
|
-
if (thisStreamConfig.externalDispose) {
|
|
53
|
-
externalPromises.push(thisStreamConfig.externalDispose.promise);
|
|
54
|
-
}
|
|
55
52
|
const owner = this;
|
|
56
53
|
let done = false;
|
|
57
54
|
return {
|
|
@@ -65,7 +62,7 @@ export class Dependency {
|
|
|
65
62
|
...externalPromises,
|
|
66
63
|
owner.next(),
|
|
67
64
|
]);
|
|
68
|
-
if (this.done
|
|
65
|
+
if (this.done) {
|
|
69
66
|
done = true;
|
|
70
67
|
return { done: true };
|
|
71
68
|
}
|
|
@@ -101,8 +98,7 @@ export class Dependency {
|
|
|
101
98
|
* Another subscribe for current race
|
|
102
99
|
*/
|
|
103
100
|
async next() {
|
|
104
|
-
|
|
105
|
-
await race;
|
|
101
|
+
await this.getOrCreateRace();
|
|
106
102
|
this._race = undefined;
|
|
107
103
|
if (this.done) {
|
|
108
104
|
return { done: true };
|
|
@@ -10,12 +10,23 @@ export class DependencyStream {
|
|
|
10
10
|
constructor(owner) {
|
|
11
11
|
this.owner = owner;
|
|
12
12
|
this.selfDispose = new PromiseConfiguration();
|
|
13
|
-
this.iterator = owner[symAI](
|
|
13
|
+
this.iterator = owner[symAI]();
|
|
14
14
|
}
|
|
15
15
|
[symAI]() {
|
|
16
|
+
const done = { done: true };
|
|
16
17
|
return {
|
|
17
|
-
next: () => {
|
|
18
|
-
|
|
18
|
+
next: async () => {
|
|
19
|
+
if (this.selfDispose.isFulfilled)
|
|
20
|
+
return done;
|
|
21
|
+
const nextRes = this.iterator.next();
|
|
22
|
+
await Promise.race([
|
|
23
|
+
this.selfDispose.promise,
|
|
24
|
+
nextRes,
|
|
25
|
+
]);
|
|
26
|
+
if (this.selfDispose.isFulfilled)
|
|
27
|
+
return done;
|
|
28
|
+
this.selfDispose = new PromiseConfiguration();
|
|
29
|
+
return nextRes;
|
|
19
30
|
}
|
|
20
31
|
};
|
|
21
32
|
}
|
|
@@ -6,7 +6,7 @@ export function raceStream(deps) {
|
|
|
6
6
|
.entries(deps)
|
|
7
7
|
.reduce((acc, [key, dep]) => {
|
|
8
8
|
acc[0].push(key);
|
|
9
|
-
acc[1].push(dep[symAI](
|
|
9
|
+
acc[1].push(dep[symAI]());
|
|
10
10
|
return acc;
|
|
11
11
|
}, [[], []]);
|
|
12
12
|
function isDisposed() {
|
|
@@ -18,12 +18,20 @@ export function raceStream(deps) {
|
|
|
18
18
|
return isDisposed();
|
|
19
19
|
},
|
|
20
20
|
[symAI]() {
|
|
21
|
+
const done = { done: true };
|
|
21
22
|
return {
|
|
22
23
|
next: async () => {
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
if (externalDispose.isFulfilled)
|
|
25
|
+
return done;
|
|
26
|
+
const res = await Promise.race([
|
|
27
|
+
externalDispose.promise,
|
|
28
|
+
...streams.map(s => s.next())
|
|
29
|
+
]);
|
|
30
|
+
if (externalDispose.isFulfilled)
|
|
31
|
+
return done;
|
|
32
|
+
externalDispose = new PromiseConfiguration();
|
|
33
|
+
if (res.done)
|
|
25
34
|
return res;
|
|
26
|
-
}
|
|
27
35
|
const value = keys.reduce((acc, key) => {
|
|
28
36
|
acc[key] = deps[key].value;
|
|
29
37
|
return acc;
|
package/dist/bin/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { PromiseConfiguration } from "../promise-configuration.js";
|
|
2
1
|
import { Dependency } from "./dependency.ts";
|
|
3
2
|
export interface IStreamIterator<TValue = any> {
|
|
4
3
|
owner: Dependency;
|
|
@@ -29,9 +28,4 @@ export type IThisStreamConfig = Partial<{
|
|
|
29
28
|
* stream dispose has priority over first reaction
|
|
30
29
|
*/
|
|
31
30
|
withReactionOnSubscribe: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Dispose happens anyway right after current task,
|
|
34
|
-
* wherever value of dependency was changed
|
|
35
|
-
*/
|
|
36
|
-
externalDispose: PromiseConfiguration<any>;
|
|
37
31
|
}>;
|
|
@@ -3,7 +3,7 @@ import { symAI } from "../constants.ts";
|
|
|
3
3
|
import { Dependency } from "./dependency.ts";
|
|
4
4
|
export declare class DependencyStream<T = any> implements IDependencyStream {
|
|
5
5
|
readonly owner: Dependency;
|
|
6
|
-
private
|
|
6
|
+
private selfDispose;
|
|
7
7
|
private readonly iterator;
|
|
8
8
|
get isDisposed(): boolean;
|
|
9
9
|
constructor(owner: Dependency);
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fbltd/async",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.38",
|
|
4
4
|
"description": "Miscellaneous async utils",
|
|
5
5
|
"homepage": "https://github.com/GlennMiller1991/async",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"typescript": "^5.x.x"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
|
-
"react": "^19.
|
|
45
|
+
"react": "^19.x.x"
|
|
46
46
|
},
|
|
47
47
|
"publishConfig": {
|
|
48
48
|
"access": "public"
|