@fbltd/async 1.0.16 → 1.0.18
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/README.md +1 -1
- package/dist/bin/delay.js +1 -1
- package/dist/bin/dependency-stream/{dependency-stream.js → dependency.js} +7 -5
- package/dist/bin/dependency-stream/dependency.stream.js +27 -0
- package/dist/bin/dependency-stream/index.js +2 -2
- package/dist/bin/dependency-stream/utils/next.js +18 -9
- package/dist/bin/dependency-stream/utils/once.stream.js +6 -10
- package/dist/bin/dependency-stream/utils/race.stream.js +1 -1
- package/dist/bin/dependency-stream/utils.js +3 -0
- package/dist/bin/index.js +1 -1
- package/dist/types/dependency-stream/contracts.d.ts +17 -11
- package/dist/types/dependency-stream/dependency.d.ts +26 -0
- package/dist/types/dependency-stream/dependency.stream.d.ts +14 -0
- package/dist/types/dependency-stream/index.d.ts +2 -2
- package/dist/types/dependency-stream/integrations/react/src/use-stream.d.ts +2 -2
- package/dist/types/dependency-stream/utils/next.d.ts +5 -6
- package/dist/types/dependency-stream/utils/once.stream.d.ts +3 -3
- package/dist/types/dependency-stream/utils/race.stream.d.ts +4 -4
- package/dist/types/dependency-stream/utils.d.ts +1 -0
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/tsconfig.json +1 -0
- package/dist/types/dependency-stream/dependency-stream.d.ts +0 -26
- /package/dist/bin/{get-promise.js → promise-configuration.js} +0 -0
- /package/dist/types/{get-promise.d.ts → promise-configuration.d.ts} +0 -0
package/README.md
CHANGED
package/dist/bin/delay.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { PromiseConfiguration } from "../
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export class DependencyStream {
|
|
1
|
+
import { PromiseConfiguration } from "../promise-configuration.js";
|
|
2
|
+
import { DependencyStream } from "./dependency.stream.js";
|
|
3
|
+
import { baseComparer } from "./utils.js";
|
|
4
|
+
export class Dependency {
|
|
6
5
|
_value;
|
|
7
6
|
reactionPromise;
|
|
8
7
|
abortPromise = new PromiseConfiguration();
|
|
@@ -31,6 +30,9 @@ export class DependencyStream {
|
|
|
31
30
|
get value() {
|
|
32
31
|
return this._value;
|
|
33
32
|
}
|
|
33
|
+
getStream() {
|
|
34
|
+
return new DependencyStream(this);
|
|
35
|
+
}
|
|
34
36
|
[Symbol.asyncIterator](thisStreamConfig = {}) {
|
|
35
37
|
const totalDispose = this.abortPromise;
|
|
36
38
|
const externalPromises = [totalDispose.promise];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { PromiseConfiguration } from "../promise-configuration.js";
|
|
2
|
+
import { symAI } from "../constants.js";
|
|
3
|
+
export class DependencyStream {
|
|
4
|
+
owner;
|
|
5
|
+
selfDispose = new PromiseConfiguration();
|
|
6
|
+
iterator;
|
|
7
|
+
get isDisposed() {
|
|
8
|
+
return this.iterator.isDisposed;
|
|
9
|
+
}
|
|
10
|
+
constructor(owner) {
|
|
11
|
+
this.owner = owner;
|
|
12
|
+
this.selfDispose = new PromiseConfiguration();
|
|
13
|
+
this.iterator = owner[symAI]({ externalDispose: this.selfDispose });
|
|
14
|
+
}
|
|
15
|
+
[symAI]() {
|
|
16
|
+
return {
|
|
17
|
+
next: () => {
|
|
18
|
+
return this.iterator.next();
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
dispose() {
|
|
23
|
+
if (this.isDisposed)
|
|
24
|
+
return;
|
|
25
|
+
this.selfDispose.resolve();
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { symAI } from "../../constants.js";
|
|
2
|
-
|
|
3
|
-
export async function next(dep) {
|
|
4
|
-
const res = await dep[symAI]().next();
|
|
5
|
-
if (res.done) {
|
|
6
|
-
throw StreamFinishError;
|
|
7
|
-
}
|
|
8
|
-
return res.value;
|
|
9
|
-
}
|
|
2
|
+
import { PromiseConfiguration } from "../../promise-configuration.js";
|
|
10
3
|
/**
|
|
11
4
|
* @internal
|
|
12
5
|
*/
|
|
13
|
-
export const
|
|
6
|
+
export const StreamFinishError = new Error("Stream is done");
|
|
7
|
+
export function next(dep) {
|
|
8
|
+
const disposePromise = new PromiseConfiguration();
|
|
9
|
+
const resultPromise = new PromiseConfiguration();
|
|
10
|
+
dep[symAI]({ externalDispose: disposePromise })
|
|
11
|
+
.next()
|
|
12
|
+
.then((res) => {
|
|
13
|
+
if (res.done)
|
|
14
|
+
resultPromise.reject(StreamFinishError);
|
|
15
|
+
else
|
|
16
|
+
resultPromise.resolve(res.value);
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
promise: resultPromise.promise,
|
|
20
|
+
dispose: () => disposePromise.resolve()
|
|
21
|
+
};
|
|
22
|
+
}
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { PromiseConfiguration } from "../../get-promise.js";
|
|
2
1
|
import { symAI } from "../../constants.js";
|
|
3
2
|
export function onceStream(dep) {
|
|
4
|
-
const
|
|
5
|
-
const iterator =
|
|
6
|
-
function isDisposed() {
|
|
7
|
-
return externalDispose.isFulfilled || iterator.isDisposed;
|
|
8
|
-
}
|
|
3
|
+
const stream = dep.getStream();
|
|
4
|
+
const iterator = stream[symAI]();
|
|
9
5
|
return {
|
|
10
6
|
get isDisposed() {
|
|
11
|
-
return isDisposed
|
|
7
|
+
return stream.isDisposed;
|
|
12
8
|
},
|
|
13
|
-
dispose:
|
|
9
|
+
dispose: () => stream.dispose(),
|
|
14
10
|
[symAI]() {
|
|
15
11
|
return {
|
|
16
12
|
next: async () => {
|
|
17
13
|
const result = await iterator.next();
|
|
18
|
-
if (!
|
|
19
|
-
|
|
14
|
+
if (!result.done)
|
|
15
|
+
stream.dispose();
|
|
20
16
|
return result;
|
|
21
17
|
}
|
|
22
18
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { symAI } from "../../constants.js";
|
|
2
|
-
import { PromiseConfiguration } from "../../
|
|
2
|
+
import { PromiseConfiguration } from "../../promise-configuration.js";
|
|
3
3
|
export function raceStream(...deps) {
|
|
4
4
|
let selfDisposePromise = new PromiseConfiguration();
|
|
5
5
|
let isDisposed = false;
|
package/dist/bin/index.js
CHANGED
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
dispose(): void;
|
|
4
|
-
}
|
|
5
|
-
export type IStreamReturn = void;
|
|
6
|
-
export type IStreamIteratorReturn = IteratorReturnResult<IStreamReturn>;
|
|
7
|
-
export type IStreamIteratorYield<T> = IteratorYieldResult<T>;
|
|
1
|
+
import { PromiseConfiguration } from "../promise-configuration.js";
|
|
2
|
+
import { Dependency } from "./dependency.ts";
|
|
8
3
|
export interface IStreamIterator<TValue = any> {
|
|
9
|
-
owner:
|
|
4
|
+
owner: Dependency;
|
|
10
5
|
dispose(): void;
|
|
11
6
|
readonly isDisposed: boolean;
|
|
12
|
-
next(): Promise<IteratorResult<TValue,
|
|
7
|
+
next(): Promise<IteratorResult<TValue, void>>;
|
|
13
8
|
}
|
|
14
|
-
export interface
|
|
9
|
+
export interface IDependencyStream<TValue = any> {
|
|
15
10
|
dispose(): void;
|
|
16
11
|
readonly isDisposed: boolean;
|
|
17
|
-
[Symbol.asyncIterator](): AsyncIterator<TValue,
|
|
12
|
+
[Symbol.asyncIterator](): AsyncIterator<TValue, void>;
|
|
13
|
+
}
|
|
14
|
+
export interface IIsEquals<T> {
|
|
15
|
+
(prev: T, cur: T): boolean;
|
|
18
16
|
}
|
|
17
|
+
export type IAllStreamConfig<T> = {
|
|
18
|
+
withCustomEquality: IIsEquals<T>;
|
|
19
|
+
withReactionOnSubscribe: boolean;
|
|
20
|
+
};
|
|
21
|
+
export type IThisStreamConfig = Partial<{
|
|
22
|
+
withReactionOnSubscribe: boolean;
|
|
23
|
+
externalDispose: PromiseConfiguration<any>;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { IAllStreamConfig, IThisStreamConfig } from "./contracts.ts";
|
|
2
|
+
import { DependencyStream } from "./dependency.stream.ts";
|
|
3
|
+
export declare class Dependency<T = any> {
|
|
4
|
+
private _value;
|
|
5
|
+
private reactionPromise;
|
|
6
|
+
private abortPromise;
|
|
7
|
+
private config;
|
|
8
|
+
constructor(_value: T, config?: Partial<IAllStreamConfig<T>>);
|
|
9
|
+
private _set;
|
|
10
|
+
set value(v: T);
|
|
11
|
+
get value(): T;
|
|
12
|
+
getStream(this: Dependency<T>): DependencyStream<T>;
|
|
13
|
+
[Symbol.asyncIterator](this: Dependency<T>, thisStreamConfig?: IThisStreamConfig): {
|
|
14
|
+
owner: Dependency<T>;
|
|
15
|
+
dispose: () => void;
|
|
16
|
+
readonly isDisposed: boolean;
|
|
17
|
+
next: () => Promise<{
|
|
18
|
+
done: true;
|
|
19
|
+
value: void;
|
|
20
|
+
} | {
|
|
21
|
+
done: boolean;
|
|
22
|
+
readonly value: T;
|
|
23
|
+
}>;
|
|
24
|
+
};
|
|
25
|
+
dispose(this: Dependency<T>): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { IDependencyStream } from "./contracts.ts";
|
|
2
|
+
import { symAI } from "../constants.ts";
|
|
3
|
+
import { Dependency } from "./dependency.ts";
|
|
4
|
+
export declare class DependencyStream<T = any> implements IDependencyStream {
|
|
5
|
+
readonly owner: Dependency;
|
|
6
|
+
private readonly selfDispose;
|
|
7
|
+
private readonly iterator;
|
|
8
|
+
get isDisposed(): boolean;
|
|
9
|
+
constructor(owner: Dependency);
|
|
10
|
+
[symAI](): {
|
|
11
|
+
next: () => Promise<IteratorResult<T, void>>;
|
|
12
|
+
};
|
|
13
|
+
dispose(): void;
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function useStream(...streams:
|
|
1
|
+
import { Dependency } from "../../../index";
|
|
2
|
+
export declare function useStream(...streams: Dependency[]): {
|
|
3
3
|
value: Array<any> | undefined;
|
|
4
4
|
dispose: () => void;
|
|
5
5
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare function next<T>(dep:
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export declare const InternalStreamFinishError: Error;
|
|
1
|
+
import { Dependency } from "../dependency.ts";
|
|
2
|
+
export declare function next<T>(dep: Dependency<T>): {
|
|
3
|
+
promise: Promise<T>;
|
|
4
|
+
dispose: () => void;
|
|
5
|
+
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function onceStream<T>(dep:
|
|
1
|
+
import { Dependency } from "../dependency.ts";
|
|
2
|
+
import { IDependencyStream } from "../contracts.ts";
|
|
3
|
+
export declare function onceStream<T>(dep: Dependency<T>): IDependencyStream<T>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Dependency } from "../dependency.ts";
|
|
2
2
|
import { symAI } from "../../constants.ts";
|
|
3
|
-
export declare function raceStream<TArray extends
|
|
3
|
+
export declare function raceStream<TArray extends Dependency[]>(...deps: NoInfer<TArray>): {
|
|
4
4
|
dispose: () => void;
|
|
5
5
|
readonly isDisposed: boolean;
|
|
6
6
|
[Symbol.asyncIterator](): {
|
|
7
|
-
next: () => Promise<
|
|
7
|
+
next: () => Promise<{
|
|
8
8
|
done: boolean;
|
|
9
|
-
value: any
|
|
9
|
+
readonly value: any;
|
|
10
10
|
}>;
|
|
11
11
|
};
|
|
12
12
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function baseComparer<T>(prev: T, cur: T): boolean;
|
package/dist/types/index.d.ts
CHANGED
package/package.json
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { IIteratorOwner, IStreamIterator } from "./contracts.ts";
|
|
2
|
-
import { PromiseConfiguration } from "../get-promise.ts";
|
|
3
|
-
interface IIsEquals<T> {
|
|
4
|
-
(prev: T, cur: T): boolean;
|
|
5
|
-
}
|
|
6
|
-
type IAllStreamConfig<T> = {
|
|
7
|
-
withCustomEquality: IIsEquals<T>;
|
|
8
|
-
withReactionOnSubscribe: boolean;
|
|
9
|
-
};
|
|
10
|
-
type IThisStreamConfig = Partial<{
|
|
11
|
-
withReactionOnSubscribe: boolean;
|
|
12
|
-
externalDispose: PromiseConfiguration<any>;
|
|
13
|
-
}>;
|
|
14
|
-
export declare class DependencyStream<T = any> implements IIteratorOwner<T> {
|
|
15
|
-
private _value;
|
|
16
|
-
private reactionPromise;
|
|
17
|
-
private abortPromise;
|
|
18
|
-
private config;
|
|
19
|
-
constructor(_value: T, config?: Partial<IAllStreamConfig<T>>);
|
|
20
|
-
private _set;
|
|
21
|
-
set value(v: T);
|
|
22
|
-
get value(): T;
|
|
23
|
-
[Symbol.asyncIterator](this: DependencyStream<T>, thisStreamConfig?: IThisStreamConfig): IStreamIterator<T>;
|
|
24
|
-
dispose(this: DependencyStream<T>): void;
|
|
25
|
-
}
|
|
26
|
-
export {};
|
|
File without changes
|
|
File without changes
|