@fbltd/async 1.0.15 → 1.0.16
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 +7 -7
- package/dist/bin/delay.js +2 -2
- package/dist/bin/dependency-stream/dependency-stream.js +5 -5
- package/dist/bin/dependency-stream/utils/once.stream.js +2 -2
- package/dist/bin/dependency-stream/utils/race.stream.js +2 -2
- package/dist/bin/get-promise.js +28 -27
- package/dist/types/dependency-stream/dependency-stream.d.ts +2 -2
- package/dist/types/get-promise.d.ts +11 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,15 +19,15 @@ await delay(number);
|
|
|
19
19
|
delay(number, 'sync');
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
###
|
|
23
|
-
|
|
24
|
-
and status flags.
|
|
25
|
-
|
|
22
|
+
### PromiseConfiguration
|
|
23
|
+
PromiseConfiguration is a class that creates and provide promise,
|
|
24
|
+
its fulfillment functions and status flags.
|
|
25
|
+
Instance of the class is represented by the following type:
|
|
26
26
|
```typescript
|
|
27
27
|
type IPromiseConfiguration<T> = {
|
|
28
|
-
resolve(arg: T)
|
|
29
|
-
reject(err: Error)
|
|
30
|
-
promise: Promise<T>, // promise itself
|
|
28
|
+
readonly resolve: (arg: T) => void, // function that resolves promise
|
|
29
|
+
readonly reject: (err: Error) => void, // function that rejects promise
|
|
30
|
+
readonly promise: Promise<T>, // promise itself
|
|
31
31
|
readonly isPending: boolean, // promise status flag
|
|
32
32
|
readonly isFulfilled: boolean, // reverted promise status flag
|
|
33
33
|
}
|
package/dist/bin/delay.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromiseConfiguration } from "./get-promise.js";
|
|
2
2
|
export function delay(ms = 0, syncKey) {
|
|
3
3
|
ms = Math.max(ms, 0);
|
|
4
4
|
return delay.methods[typeof syncKey](ms);
|
|
@@ -14,7 +14,7 @@ Object.defineProperty(delay, 'methods', {
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
undefined: (ms) => {
|
|
17
|
-
const { promise, resolve } =
|
|
17
|
+
const { promise, resolve } = new PromiseConfiguration();
|
|
18
18
|
setTimeout(() => {
|
|
19
19
|
resolve();
|
|
20
20
|
}, ms);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromiseConfiguration } from "../get-promise.js";
|
|
2
2
|
function baseComparer(prev, cur) {
|
|
3
3
|
return prev === cur;
|
|
4
4
|
}
|
|
5
5
|
export class DependencyStream {
|
|
6
6
|
_value;
|
|
7
7
|
reactionPromise;
|
|
8
|
-
abortPromise =
|
|
8
|
+
abortPromise = new PromiseConfiguration();
|
|
9
9
|
config;
|
|
10
10
|
constructor(_value, config = {}) {
|
|
11
11
|
this._value = _value;
|
|
@@ -37,7 +37,7 @@ export class DependencyStream {
|
|
|
37
37
|
let firstPromise;
|
|
38
38
|
const withReactionOnSubscribe = this.config.withReactionOnSubscribe || thisStreamConfig.withReactionOnSubscribe;
|
|
39
39
|
if (withReactionOnSubscribe) {
|
|
40
|
-
firstPromise =
|
|
40
|
+
firstPromise = new PromiseConfiguration();
|
|
41
41
|
firstPromise.resolve(this.value);
|
|
42
42
|
externalPromises.push(firstPromise.promise);
|
|
43
43
|
}
|
|
@@ -54,7 +54,7 @@ export class DependencyStream {
|
|
|
54
54
|
},
|
|
55
55
|
next: async () => {
|
|
56
56
|
if (!this.reactionPromise) {
|
|
57
|
-
this.reactionPromise =
|
|
57
|
+
this.reactionPromise = new PromiseConfiguration();
|
|
58
58
|
this._set(this._value);
|
|
59
59
|
}
|
|
60
60
|
await Promise.race([
|
|
@@ -80,7 +80,7 @@ export class DependencyStream {
|
|
|
80
80
|
}
|
|
81
81
|
dispose() {
|
|
82
82
|
this.abortPromise.resolve();
|
|
83
|
-
this.abortPromise =
|
|
83
|
+
this.abortPromise = new PromiseConfiguration();
|
|
84
84
|
this.reactionPromise = undefined;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PromiseConfiguration } from "../../get-promise.js";
|
|
2
2
|
import { symAI } from "../../constants.js";
|
|
3
3
|
export function onceStream(dep) {
|
|
4
|
-
const externalDispose =
|
|
4
|
+
const externalDispose = new PromiseConfiguration();
|
|
5
5
|
const iterator = dep[symAI]({ externalDispose });
|
|
6
6
|
function isDisposed() {
|
|
7
7
|
return externalDispose.isFulfilled || iterator.isDisposed;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { symAI } from "../../constants.js";
|
|
2
|
-
import {
|
|
2
|
+
import { PromiseConfiguration } from "../../get-promise.js";
|
|
3
3
|
export function raceStream(...deps) {
|
|
4
|
-
let selfDisposePromise =
|
|
4
|
+
let selfDisposePromise = new PromiseConfiguration();
|
|
5
5
|
let isDisposed = false;
|
|
6
6
|
const streams = deps.map((dep) => dep[symAI]({
|
|
7
7
|
externalDispose: selfDisposePromise
|
package/dist/bin/get-promise.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export class PromiseConfiguration {
|
|
2
|
+
promise;
|
|
3
|
+
_resolve;
|
|
4
|
+
_reject;
|
|
5
|
+
_isFulfilled = false;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.promise = new Promise((res, rej) => {
|
|
8
|
+
this._resolve = ((value) => {
|
|
9
|
+
res(value);
|
|
10
|
+
this._isFulfilled = true;
|
|
11
|
+
});
|
|
12
|
+
this._reject = (error) => {
|
|
13
|
+
rej(error);
|
|
14
|
+
this._isFulfilled = true;
|
|
15
|
+
};
|
|
11
16
|
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return isFulfilled;
|
|
26
|
-
},
|
|
27
|
-
promise
|
|
28
|
-
};
|
|
17
|
+
}
|
|
18
|
+
get reject() {
|
|
19
|
+
return this._reject;
|
|
20
|
+
}
|
|
21
|
+
get resolve() {
|
|
22
|
+
return this._resolve;
|
|
23
|
+
}
|
|
24
|
+
get isFulfilled() {
|
|
25
|
+
return this._isFulfilled;
|
|
26
|
+
}
|
|
27
|
+
get isPending() {
|
|
28
|
+
return !this.isFulfilled;
|
|
29
|
+
}
|
|
29
30
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { IPromiseConfiguration } from "../get-promise.ts";
|
|
2
1
|
import { IIteratorOwner, IStreamIterator } from "./contracts.ts";
|
|
2
|
+
import { PromiseConfiguration } from "../get-promise.ts";
|
|
3
3
|
interface IIsEquals<T> {
|
|
4
4
|
(prev: T, cur: T): boolean;
|
|
5
5
|
}
|
|
@@ -9,7 +9,7 @@ type IAllStreamConfig<T> = {
|
|
|
9
9
|
};
|
|
10
10
|
type IThisStreamConfig = Partial<{
|
|
11
11
|
withReactionOnSubscribe: boolean;
|
|
12
|
-
externalDispose:
|
|
12
|
+
externalDispose: PromiseConfiguration<any>;
|
|
13
13
|
}>;
|
|
14
14
|
export declare class DependencyStream<T = any> implements IIteratorOwner<T> {
|
|
15
15
|
private _value;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
export declare
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
export declare class PromiseConfiguration<TReturn = void> {
|
|
2
|
+
readonly promise: Promise<TReturn>;
|
|
3
|
+
_resolve: (value: TReturn) => void;
|
|
4
|
+
_reject: (value: Error) => void;
|
|
5
|
+
_isFulfilled: boolean;
|
|
6
|
+
constructor();
|
|
7
|
+
get reject(): (value: Error) => void;
|
|
8
|
+
get resolve(): (value: TReturn) => void;
|
|
9
|
+
get isFulfilled(): boolean;
|
|
10
|
+
get isPending(): boolean;
|
|
11
|
+
}
|