@fbltd/async 1.0.10 → 1.0.12
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/index.js +17 -5
- package/dist/bin/dependency-stream/utils/next.js +7 -0
- package/dist/bin/dependency-stream/utils/once.stream.js +28 -0
- package/dist/bin/dependency-stream/utils/race.stream.js +7 -7
- package/dist/types/dependency-stream/contracts.d.ts +18 -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/index.d.ts +3 -2
- package/dist/types/dependency-stream/utils/next.d.ts +2 -0
- package/dist/types/dependency-stream/utils/once.stream.d.ts +3 -0
- package/dist/types/dependency-stream/utils/race.stream.d.ts +3 -6
- package/package.json +1 -1
- package/dist/bin/dependency-stream/utils/once.js +0 -19
- package/dist/types/dependency-stream/utils/once.d.ts +0 -12
|
@@ -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
|
}
|
|
@@ -1,7 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var race_stream_1 = require("./race.stream");
|
|
7
|
-
Object.defineProperty(exports, "raceStream", { enumerable: true, get: function () { return race_stream_1.raceStream; } });
|
|
17
|
+
__exportStar(require("./once.stream"), exports);
|
|
18
|
+
__exportStar(require("./race.stream"), exports);
|
|
19
|
+
__exportStar(require("./next"), exports);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.onceStream = onceStream;
|
|
4
|
+
const get_promise_1 = require("../../get-promise");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
function onceStream(dep) {
|
|
7
|
+
const externalDispose = (0, get_promise_1.getPromise)();
|
|
8
|
+
const iterator = dep[constants_1.symAI]({ externalDispose });
|
|
9
|
+
function isDisposed() {
|
|
10
|
+
return externalDispose.isFulfilled || iterator.isDisposed;
|
|
11
|
+
}
|
|
12
|
+
return {
|
|
13
|
+
get isDisposed() {
|
|
14
|
+
return isDisposed();
|
|
15
|
+
},
|
|
16
|
+
dispose: externalDispose.resolve,
|
|
17
|
+
[constants_1.symAI]() {
|
|
18
|
+
return {
|
|
19
|
+
next: async () => {
|
|
20
|
+
const result = await iterator.next();
|
|
21
|
+
if (!isDisposed())
|
|
22
|
+
externalDispose.resolve();
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -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,18 @@
|
|
|
1
|
+
export interface IIteratorOwner<TValue = any> {
|
|
2
|
+
value: TValue;
|
|
3
|
+
dispose(): void;
|
|
4
|
+
}
|
|
5
|
+
export type IStreamReturn = void;
|
|
6
|
+
export type IStreamIteratorReturn = IteratorReturnResult<IStreamReturn>;
|
|
7
|
+
export type IStreamIteratorYield<T> = IteratorYieldResult<T>;
|
|
8
|
+
export interface IStreamIterator<TValue = any> {
|
|
9
|
+
owner: IIteratorOwner<TValue>;
|
|
10
|
+
dispose(): void;
|
|
11
|
+
readonly isDisposed: boolean;
|
|
12
|
+
next(): Promise<IteratorResult<TValue, IStreamReturn>>;
|
|
13
|
+
}
|
|
14
|
+
export interface IStreamOwner<TValue = any> {
|
|
15
|
+
dispose(): void;
|
|
16
|
+
readonly isDisposed: boolean;
|
|
17
|
+
[Symbol.asyncIterator](): AsyncIterator<TValue, IStreamReturn>;
|
|
18
|
+
}
|
|
@@ -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,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export * from "./once.stream";
|
|
2
|
+
export * from "./race.stream";
|
|
3
|
+
export * from "./next";
|
|
@@ -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
|
}>;
|
package/package.json
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.once = once;
|
|
4
|
-
function once(dep) {
|
|
5
|
-
let isIterationWas = false;
|
|
6
|
-
const iterator = dep[Symbol.asyncIterator]();
|
|
7
|
-
return {
|
|
8
|
-
[Symbol.asyncIterator]() {
|
|
9
|
-
return {
|
|
10
|
-
next: async () => {
|
|
11
|
-
if (isIterationWas)
|
|
12
|
-
return { done: true };
|
|
13
|
-
return iterator.next();
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
dispose: iterator.dispose,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { DependencyStream } from "../dependency-stream";
|
|
2
|
-
export declare function once(dep: DependencyStream): {
|
|
3
|
-
[Symbol.asyncIterator](): {
|
|
4
|
-
next: () => Promise<{
|
|
5
|
-
done: boolean;
|
|
6
|
-
readonly value: any;
|
|
7
|
-
} | {
|
|
8
|
-
done: boolean;
|
|
9
|
-
}>;
|
|
10
|
-
};
|
|
11
|
-
dispose: () => void;
|
|
12
|
-
};
|