@fbltd/async 1.0.10 → 1.0.11
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-stream/contracts.js +2 -0
- package/dist/bin/dependency-stream/dependency-stream.js +8 -6
- package/dist/bin/dependency-stream/index.js +1 -0
- package/dist/bin/dependency-stream/utils/race.stream.js +7 -7
- package/dist/types/dependency-stream/contracts.d.ts +10 -0
- package/dist/types/dependency-stream/dependency-stream.d.ts +5 -13
- package/dist/types/dependency-stream/index.d.ts +1 -0
- package/dist/types/dependency-stream/utils/once.d.ts +1 -4
- package/dist/types/dependency-stream/utils/race.stream.d.ts +3 -6
- package/package.json +1 -1
|
@@ -36,20 +36,22 @@ class DependencyStream {
|
|
|
36
36
|
}
|
|
37
37
|
[Symbol.asyncIterator](thisStreamConfig = {}) {
|
|
38
38
|
const totalDispose = this.abortPromise;
|
|
39
|
-
const
|
|
40
|
-
const externalPromises = [totalDispose.promise, selfDispose.promise];
|
|
39
|
+
const externalPromises = [totalDispose.promise];
|
|
41
40
|
let firstPromise;
|
|
42
|
-
|
|
41
|
+
const withReactionOnSubscribe = this.config.withReactionOnSubscribe || thisStreamConfig.withReactionOnSubscribe;
|
|
42
|
+
if (withReactionOnSubscribe) {
|
|
43
43
|
firstPromise = (0, get_promise_1.getPromise)();
|
|
44
44
|
firstPromise.resolve(this.value);
|
|
45
45
|
externalPromises.push(firstPromise.promise);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
if (thisStreamConfig.externalDispose) {
|
|
48
|
+
externalPromises.push(thisStreamConfig.externalDispose.promise);
|
|
49
|
+
}
|
|
48
50
|
let isDisposed = false;
|
|
49
51
|
const owner = this;
|
|
50
52
|
return {
|
|
51
53
|
owner,
|
|
52
|
-
dispose:
|
|
54
|
+
dispose: owner.dispose.bind(owner),
|
|
53
55
|
get isDisposed() {
|
|
54
56
|
return isDisposed;
|
|
55
57
|
},
|
|
@@ -62,7 +64,7 @@ class DependencyStream {
|
|
|
62
64
|
...externalPromises,
|
|
63
65
|
this.reactionPromise.promise,
|
|
64
66
|
]);
|
|
65
|
-
if (totalDispose.isFulfilled ||
|
|
67
|
+
if (totalDispose.isFulfilled || thisStreamConfig.externalDispose?.isFulfilled) {
|
|
66
68
|
isDisposed = true;
|
|
67
69
|
return { done: true };
|
|
68
70
|
}
|
|
@@ -4,22 +4,22 @@ exports.raceStream = raceStream;
|
|
|
4
4
|
const constants_1 = require("../../constants");
|
|
5
5
|
const get_promise_1 = require("../../get-promise");
|
|
6
6
|
function raceStream(...deps) {
|
|
7
|
-
const streams = deps.map((dep) => dep[constants_1.symAI]());
|
|
8
7
|
let selfDisposePromise = (0, get_promise_1.getPromise)();
|
|
9
8
|
let isDisposed = false;
|
|
9
|
+
const streams = deps.map((dep) => dep[constants_1.symAI]({
|
|
10
|
+
externalDispose: selfDisposePromise
|
|
11
|
+
}));
|
|
10
12
|
return {
|
|
11
|
-
dispose: selfDisposePromise.resolve,
|
|
13
|
+
dispose: () => selfDisposePromise.resolve({ done: true, value: void 0 }),
|
|
12
14
|
get isDisposed() {
|
|
13
15
|
return isDisposed;
|
|
14
16
|
},
|
|
15
17
|
[constants_1.symAI]() {
|
|
16
18
|
return {
|
|
17
19
|
next: async () => {
|
|
18
|
-
await Promise.race([selfDisposePromise.promise, streams.map(s => s.next())]);
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
return { done: true };
|
|
22
|
-
}
|
|
20
|
+
const res = await Promise.race([selfDisposePromise.promise, ...streams.map(s => s.next())]);
|
|
21
|
+
if (res.done)
|
|
22
|
+
return res;
|
|
23
23
|
return { done: false, value: streams.map(s => s.owner.value) };
|
|
24
24
|
}
|
|
25
25
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface IIteratorOwner<TValue = any> {
|
|
2
|
+
value: TValue;
|
|
3
|
+
dispose(): void;
|
|
4
|
+
}
|
|
5
|
+
export interface IStreamIterator<TValue = any> {
|
|
6
|
+
owner: IIteratorOwner<TValue>;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
readonly isDisposed: boolean;
|
|
9
|
+
next(): Promise<IteratorResult<TValue, void>>;
|
|
10
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { IPromiseConfiguration } from "../get-promise";
|
|
2
|
+
import { IIteratorOwner, IStreamIterator } from "./contracts";
|
|
1
3
|
interface IIsEquals<T> {
|
|
2
4
|
(prev: T, cur: T): boolean;
|
|
3
5
|
}
|
|
@@ -7,8 +9,9 @@ type IAllStreamConfig<T> = {
|
|
|
7
9
|
};
|
|
8
10
|
type IThisStreamConfig = Partial<{
|
|
9
11
|
withReactionOnSubscribe: boolean;
|
|
12
|
+
externalDispose: IPromiseConfiguration<any>;
|
|
10
13
|
}>;
|
|
11
|
-
export declare class DependencyStream<T = any> {
|
|
14
|
+
export declare class DependencyStream<T = any> implements IIteratorOwner<T> {
|
|
12
15
|
private _value;
|
|
13
16
|
private reactionPromise;
|
|
14
17
|
private abortPromise;
|
|
@@ -17,18 +20,7 @@ export declare class DependencyStream<T = any> {
|
|
|
17
20
|
private _set;
|
|
18
21
|
set value(v: T);
|
|
19
22
|
get value(): T;
|
|
20
|
-
[Symbol.asyncIterator](this: DependencyStream<T>, thisStreamConfig?: IThisStreamConfig):
|
|
21
|
-
owner: DependencyStream<T>;
|
|
22
|
-
dispose: () => void;
|
|
23
|
-
readonly isDisposed: boolean;
|
|
24
|
-
next: () => Promise<{
|
|
25
|
-
done: boolean;
|
|
26
|
-
readonly value?: undefined;
|
|
27
|
-
} | {
|
|
28
|
-
done: boolean;
|
|
29
|
-
readonly value: T;
|
|
30
|
-
}>;
|
|
31
|
-
};
|
|
23
|
+
[Symbol.asyncIterator](this: DependencyStream<T>, thisStreamConfig?: IThisStreamConfig): IStreamIterator<T>;
|
|
32
24
|
dispose(this: DependencyStream<T>): void;
|
|
33
25
|
}
|
|
34
26
|
export {};
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { DependencyStream } from "../dependency-stream";
|
|
2
2
|
export declare function once(dep: DependencyStream): {
|
|
3
3
|
[Symbol.asyncIterator](): {
|
|
4
|
-
next: () => Promise<{
|
|
5
|
-
done: boolean;
|
|
6
|
-
readonly value: any;
|
|
7
|
-
} | {
|
|
4
|
+
next: () => Promise<IteratorYieldResult<any> | IteratorReturnResult<void> | {
|
|
8
5
|
done: boolean;
|
|
9
6
|
}>;
|
|
10
7
|
};
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
import { DependencyStream } from "../dependency-stream";
|
|
2
2
|
import { symAI } from "../../constants";
|
|
3
|
-
export declare function raceStream(...deps:
|
|
4
|
-
dispose: (
|
|
3
|
+
export declare function raceStream<TArray extends DependencyStream[]>(...deps: NoInfer<TArray>): {
|
|
4
|
+
dispose: () => void;
|
|
5
5
|
readonly isDisposed: boolean;
|
|
6
6
|
[Symbol.asyncIterator](): {
|
|
7
|
-
next: () => Promise<{
|
|
8
|
-
done: boolean;
|
|
9
|
-
readonly value?: undefined;
|
|
10
|
-
} | {
|
|
7
|
+
next: () => Promise<IteratorReturnResult<void> | {
|
|
11
8
|
done: boolean;
|
|
12
9
|
value: any[];
|
|
13
10
|
}>;
|