@thi.ng/rstream 8.2.13 → 8.2.14
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/CHANGELOG.md +1 -1
- package/api.js +18 -26
- package/asidechain.js +18 -19
- package/atom.js +17 -46
- package/bisect.js +8 -49
- package/checks.js +6 -7
- package/debounce.js +9 -17
- package/defworker.js +8 -6
- package/event.js +13 -38
- package/forkjoin.js +38 -104
- package/idgen.js +6 -8
- package/internal/remove.js +9 -6
- package/interval.js +21 -29
- package/iterable.js +21 -43
- package/logger.js +6 -2
- package/merge.js +71 -117
- package/metastream.js +66 -142
- package/nodejs.js +11 -51
- package/object.js +34 -98
- package/package.json +14 -11
- package/post-worker.js +29 -60
- package/promise.js +30 -36
- package/promises.js +7 -41
- package/pubsub.js +91 -105
- package/raf.js +16 -28
- package/resolve.js +37 -58
- package/sidechain-partition.js +36 -89
- package/sidechain-toggle.js +27 -48
- package/sidechain-trigger.js +26 -60
- package/stream.js +67 -74
- package/subscription.js +214 -275
- package/sync-raf.js +35 -66
- package/sync.js +133 -176
- package/timeout.js +38 -49
- package/toggle.js +10 -29
- package/trace.js +14 -18
- package/transduce.js +43 -60
- package/trigger.js +5 -2
- package/tunnel.js +55 -62
- package/tween.js +26 -76
- package/view.js +22 -43
- package/worker.js +24 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/rstream",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.14",
|
|
4
4
|
"description": "Reactive streams & subscription primitives for constructing dataflow graphs / pipelines",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -28,7 +28,9 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "Apache-2.0",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"build": "yarn
|
|
31
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
32
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
33
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
32
34
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc internal",
|
|
33
35
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
34
36
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -37,17 +39,18 @@
|
|
|
37
39
|
"test": "bun test"
|
|
38
40
|
},
|
|
39
41
|
"dependencies": {
|
|
40
|
-
"@thi.ng/api": "^8.9.
|
|
41
|
-
"@thi.ng/arrays": "^2.7.
|
|
42
|
-
"@thi.ng/associative": "^6.3.
|
|
43
|
-
"@thi.ng/atom": "^5.2.
|
|
44
|
-
"@thi.ng/checks": "^3.4.
|
|
45
|
-
"@thi.ng/errors": "^2.4.
|
|
46
|
-
"@thi.ng/logger": "^2.0.
|
|
47
|
-
"@thi.ng/transducers": "^8.8.
|
|
42
|
+
"@thi.ng/api": "^8.9.12",
|
|
43
|
+
"@thi.ng/arrays": "^2.7.8",
|
|
44
|
+
"@thi.ng/associative": "^6.3.24",
|
|
45
|
+
"@thi.ng/atom": "^5.2.18",
|
|
46
|
+
"@thi.ng/checks": "^3.4.12",
|
|
47
|
+
"@thi.ng/errors": "^2.4.6",
|
|
48
|
+
"@thi.ng/logger": "^2.0.2",
|
|
49
|
+
"@thi.ng/transducers": "^8.8.15"
|
|
48
50
|
},
|
|
49
51
|
"devDependencies": {
|
|
50
52
|
"@microsoft/api-extractor": "^7.38.3",
|
|
53
|
+
"esbuild": "^0.19.8",
|
|
51
54
|
"rimraf": "^5.0.5",
|
|
52
55
|
"tools": "^0.0.1",
|
|
53
56
|
"typedoc": "^0.25.4",
|
|
@@ -212,5 +215,5 @@
|
|
|
212
215
|
],
|
|
213
216
|
"year": 2017
|
|
214
217
|
},
|
|
215
|
-
"gitHead": "
|
|
218
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
216
219
|
}
|
package/post-worker.js
CHANGED
|
@@ -2,64 +2,33 @@ import { isTransferable } from "@thi.ng/checks/is-transferable";
|
|
|
2
2
|
import { isTypedArray } from "@thi.ng/checks/is-typedarray";
|
|
3
3
|
import { LOGGER } from "./logger.js";
|
|
4
4
|
import { defWorker } from "./defworker.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
* @param worker -
|
|
36
|
-
* @param transfer -
|
|
37
|
-
* @param terminate - worker termination delay (ms)
|
|
38
|
-
*/
|
|
39
|
-
export const postWorker = (worker, transfer = false, terminate = 0) => {
|
|
40
|
-
const _worker = defWorker(worker);
|
|
41
|
-
return {
|
|
42
|
-
next(x) {
|
|
43
|
-
if (x instanceof Promise) {
|
|
44
|
-
x.then((y) => this.next(y));
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
let tx;
|
|
48
|
-
if (transfer) {
|
|
49
|
-
const ta = isTypedArray(x);
|
|
50
|
-
if (ta || isTransferable(x)) {
|
|
51
|
-
tx = [ta ? x.buffer : x];
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
_worker.postMessage(x, tx || []);
|
|
55
|
-
},
|
|
56
|
-
done() {
|
|
57
|
-
if (terminate > 0) {
|
|
58
|
-
setTimeout(() => {
|
|
59
|
-
LOGGER.info("terminating worker...");
|
|
60
|
-
_worker.terminate();
|
|
61
|
-
}, terminate);
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
};
|
|
5
|
+
const postWorker = (worker, transfer = false, terminate = 0) => {
|
|
6
|
+
const _worker = defWorker(worker);
|
|
7
|
+
return {
|
|
8
|
+
next(x) {
|
|
9
|
+
if (x instanceof Promise) {
|
|
10
|
+
x.then((y) => this.next(y));
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
let tx;
|
|
14
|
+
if (transfer) {
|
|
15
|
+
const ta = isTypedArray(x);
|
|
16
|
+
if (ta || isTransferable(x)) {
|
|
17
|
+
tx = [ta ? x.buffer : x];
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
_worker.postMessage(x, tx || []);
|
|
21
|
+
},
|
|
22
|
+
done() {
|
|
23
|
+
if (terminate > 0) {
|
|
24
|
+
setTimeout(() => {
|
|
25
|
+
LOGGER.info("terminating worker...");
|
|
26
|
+
_worker.terminate();
|
|
27
|
+
}, terminate);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
postWorker
|
|
65
34
|
};
|
package/promise.js
CHANGED
|
@@ -1,40 +1,34 @@
|
|
|
1
1
|
import { CloseMode, State } from "./api.js";
|
|
2
2
|
import { __optsWithID } from "./idgen.js";
|
|
3
3
|
import { stream } from "./stream.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
35
|
-
}, (e) => stream.error(e));
|
|
36
|
-
return () => {
|
|
37
|
-
canceled = true;
|
|
38
|
-
};
|
|
39
|
-
}, __optsWithID("promise", opts));
|
|
4
|
+
const fromPromise = (src, opts) => {
|
|
5
|
+
let canceled = false;
|
|
6
|
+
let isError = false;
|
|
7
|
+
let err = {};
|
|
8
|
+
src.catch((e) => {
|
|
9
|
+
err = e;
|
|
10
|
+
isError = true;
|
|
11
|
+
});
|
|
12
|
+
return stream((stream2) => {
|
|
13
|
+
src.then(
|
|
14
|
+
(x) => {
|
|
15
|
+
if (!canceled && stream2.getState() < State.DONE) {
|
|
16
|
+
if (isError) {
|
|
17
|
+
stream2.error(err);
|
|
18
|
+
err = null;
|
|
19
|
+
} else {
|
|
20
|
+
stream2.next(x);
|
|
21
|
+
stream2.closeIn !== CloseMode.NEVER && stream2.done();
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
(e) => stream2.error(e)
|
|
26
|
+
);
|
|
27
|
+
return () => {
|
|
28
|
+
canceled = true;
|
|
29
|
+
};
|
|
30
|
+
}, __optsWithID("promise", opts));
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
fromPromise
|
|
40
34
|
};
|
package/promises.js
CHANGED
|
@@ -1,44 +1,10 @@
|
|
|
1
1
|
import { mapcat } from "@thi.ng/transducers/mapcat";
|
|
2
2
|
import { __optsWithID } from "./idgen.js";
|
|
3
3
|
import { fromPromise } from "./promise.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
*
|
|
12
|
-
* @remarks
|
|
13
|
-
* Type signature updated to use `Awaited<T>`, a new core type introduced in
|
|
14
|
-
* TypeScript 4.5.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```ts
|
|
18
|
-
* fromPromises([
|
|
19
|
-
* Promise.resolve(1),
|
|
20
|
-
* Promise.resolve(2),
|
|
21
|
-
* Promise.resolve(3)
|
|
22
|
-
* ]).subscribe(trace())
|
|
23
|
-
* // 1
|
|
24
|
-
* // 2
|
|
25
|
-
* // 3
|
|
26
|
-
* // done
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* If individual error handling is required, an alternative is below
|
|
31
|
-
* (however this approach provides no ordering guarantees):
|
|
32
|
-
*
|
|
33
|
-
* ```ts
|
|
34
|
-
* fromIterable([
|
|
35
|
-
* Promise.resolve(1),
|
|
36
|
-
* new Promise(() => setTimeout(() => { throw new Error("eeek"); }, 10)),
|
|
37
|
-
* Promise.resolve(3)
|
|
38
|
-
* ]).subscribe(resolve()).subscribe(trace())
|
|
39
|
-
* ```
|
|
40
|
-
*
|
|
41
|
-
* @param promises -
|
|
42
|
-
* @param opts -
|
|
43
|
-
*/
|
|
44
|
-
export const fromPromises = (promises, opts) => fromPromise(Promise.all(promises), __optsWithID("promises", opts)).transform(mapcat((x) => x));
|
|
4
|
+
const fromPromises = (promises, opts) => fromPromise(
|
|
5
|
+
Promise.all(promises),
|
|
6
|
+
__optsWithID("promises", opts)
|
|
7
|
+
).transform(mapcat((x) => x));
|
|
8
|
+
export {
|
|
9
|
+
fromPromises
|
|
10
|
+
};
|
package/pubsub.js
CHANGED
|
@@ -1,115 +1,101 @@
|
|
|
1
1
|
import { EquivMap } from "@thi.ng/associative/equiv-map";
|
|
2
2
|
import { unsupported } from "@thi.ng/errors/unsupported";
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CloseMode
|
|
5
|
+
} from "./api.js";
|
|
4
6
|
import { __optsWithID } from "./idgen.js";
|
|
5
7
|
import { LOGGER } from "./logger.js";
|
|
6
8
|
import { Subscription, subscription } from "./subscription.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
9
|
+
const pubsub = (opts) => new PubSub(opts);
|
|
10
|
+
class PubSub extends Subscription {
|
|
11
|
+
topicfn;
|
|
12
|
+
topics;
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super(
|
|
15
|
+
void 0,
|
|
16
|
+
__optsWithID("pubsub", {
|
|
17
|
+
xform: opts.xform
|
|
18
|
+
})
|
|
19
|
+
);
|
|
20
|
+
this.topicfn = opts.topic;
|
|
21
|
+
this.topics = new EquivMap(void 0, {
|
|
22
|
+
equiv: opts.equiv
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Unsupported. Use {@link PubSub.(subscribeTopic:1)} instead.
|
|
27
|
+
*/
|
|
28
|
+
subscribe() {
|
|
29
|
+
return unsupported(`use subscribeTopic() instead`);
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Unsupported. Use {@link PubSub.(subscribeTopic:1)} instead.
|
|
33
|
+
*/
|
|
34
|
+
transform() {
|
|
35
|
+
return unsupported(`use subscribeTopic() instead`);
|
|
36
|
+
}
|
|
37
|
+
subscribeTopic(topicID, sub, opts) {
|
|
38
|
+
let t = this.topics.get(topicID);
|
|
39
|
+
!t && this.topics.set(
|
|
40
|
+
topicID,
|
|
41
|
+
t = subscription(
|
|
42
|
+
void 0,
|
|
43
|
+
__optsWithID("topic", {
|
|
44
|
+
closeOut: CloseMode.NEVER
|
|
45
|
+
})
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
return t.subscribe(sub, opts);
|
|
49
|
+
}
|
|
50
|
+
transformTopic(topicID, xform, opts = {}) {
|
|
51
|
+
return this.subscribeTopic(
|
|
52
|
+
topicID,
|
|
53
|
+
{ error: opts.error },
|
|
54
|
+
{
|
|
55
|
+
...opts,
|
|
56
|
+
xform
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
unsubscribeTopic(topicID, sub) {
|
|
61
|
+
const t = this.topics.get(topicID);
|
|
62
|
+
return t ? t.unsubscribe(sub) : false;
|
|
63
|
+
}
|
|
64
|
+
unsubscribe(sub) {
|
|
65
|
+
if (!sub) {
|
|
66
|
+
for (let t of this.topics.values()) {
|
|
67
|
+
t.unsubscribe();
|
|
68
|
+
}
|
|
69
|
+
this.topics.clear();
|
|
70
|
+
return super.unsubscribe();
|
|
49
71
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
return unsupported();
|
|
73
|
+
}
|
|
74
|
+
done() {
|
|
75
|
+
for (let t of this.topics.values()) {
|
|
76
|
+
t.done();
|
|
55
77
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return this.subscribeTopic(topicID, { error: opts.error }, {
|
|
72
|
-
...opts,
|
|
73
|
-
xform,
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
unsubscribeTopic(topicID, sub) {
|
|
77
|
-
const t = this.topics.get(topicID);
|
|
78
|
-
return t ? t.unsubscribe(sub) : false;
|
|
79
|
-
}
|
|
80
|
-
unsubscribe(sub) {
|
|
81
|
-
if (!sub) {
|
|
82
|
-
for (let t of this.topics.values()) {
|
|
83
|
-
t.unsubscribe();
|
|
84
|
-
}
|
|
85
|
-
this.topics.clear();
|
|
86
|
-
return super.unsubscribe();
|
|
87
|
-
}
|
|
88
|
-
// only the PubSub itself can be unsubscribed
|
|
89
|
-
return unsupported();
|
|
90
|
-
}
|
|
91
|
-
done() {
|
|
92
|
-
for (let t of this.topics.values()) {
|
|
93
|
-
t.done();
|
|
94
|
-
}
|
|
95
|
-
super.done();
|
|
96
|
-
}
|
|
97
|
-
dispatch(x) {
|
|
98
|
-
LOGGER.debug(this.id, "dispatch", x);
|
|
99
|
-
this.cacheLast && (this.last = x);
|
|
100
|
-
const t = this.topicfn(x);
|
|
101
|
-
if (t !== undefined) {
|
|
102
|
-
const sub = this.topics.get(t);
|
|
103
|
-
if (sub) {
|
|
104
|
-
try {
|
|
105
|
-
sub.next && sub.next(x);
|
|
106
|
-
}
|
|
107
|
-
catch (e) {
|
|
108
|
-
if (!sub.error || !sub.error(e)) {
|
|
109
|
-
return this.unhandledError(e);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
78
|
+
super.done();
|
|
79
|
+
}
|
|
80
|
+
dispatch(x) {
|
|
81
|
+
LOGGER.debug(this.id, "dispatch", x);
|
|
82
|
+
this.cacheLast && (this.last = x);
|
|
83
|
+
const t = this.topicfn(x);
|
|
84
|
+
if (t !== void 0) {
|
|
85
|
+
const sub = this.topics.get(t);
|
|
86
|
+
if (sub) {
|
|
87
|
+
try {
|
|
88
|
+
sub.next && sub.next(x);
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (!sub.error || !sub.error(e)) {
|
|
91
|
+
return this.unhandledError(e);
|
|
92
|
+
}
|
|
113
93
|
}
|
|
94
|
+
}
|
|
114
95
|
}
|
|
96
|
+
}
|
|
115
97
|
}
|
|
98
|
+
export {
|
|
99
|
+
PubSub,
|
|
100
|
+
pubsub
|
|
101
|
+
};
|
package/raf.js
CHANGED
|
@@ -2,31 +2,19 @@ import { isNode } from "@thi.ng/checks/is-node";
|
|
|
2
2
|
import { __optsWithID } from "./idgen.js";
|
|
3
3
|
import { fromInterval } from "./interval.js";
|
|
4
4
|
import { stream } from "./stream.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
let i = 0;
|
|
22
|
-
let isActive = true;
|
|
23
|
-
const loop = (time) => {
|
|
24
|
-
isActive && stream.next(opts.timestamp ? time : i++);
|
|
25
|
-
isActive && (id = requestAnimationFrame(loop));
|
|
26
|
-
};
|
|
27
|
-
let id = requestAnimationFrame(loop);
|
|
28
|
-
return () => {
|
|
29
|
-
isActive = false;
|
|
30
|
-
cancelAnimationFrame(id);
|
|
31
|
-
};
|
|
32
|
-
}, __optsWithID("raf", opts));
|
|
5
|
+
const fromRAF = (opts = {}) => isNode() ? fromInterval(16, opts) : stream((stream2) => {
|
|
6
|
+
let i = 0;
|
|
7
|
+
let isActive = true;
|
|
8
|
+
const loop = (time) => {
|
|
9
|
+
isActive && stream2.next(opts.timestamp ? time : i++);
|
|
10
|
+
isActive && (id = requestAnimationFrame(loop));
|
|
11
|
+
};
|
|
12
|
+
let id = requestAnimationFrame(loop);
|
|
13
|
+
return () => {
|
|
14
|
+
isActive = false;
|
|
15
|
+
cancelAnimationFrame(id);
|
|
16
|
+
};
|
|
17
|
+
}, __optsWithID("raf", opts));
|
|
18
|
+
export {
|
|
19
|
+
fromRAF
|
|
20
|
+
};
|
package/resolve.js
CHANGED
|
@@ -2,64 +2,43 @@ import { State } from "./api.js";
|
|
|
2
2
|
import { __optsWithID } from "./idgen.js";
|
|
3
3
|
import { LOGGER } from "./logger.js";
|
|
4
4
|
import { Subscription } from "./subscription.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
outstanding = 0;
|
|
32
|
-
fail;
|
|
33
|
-
constructor(opts = {}) {
|
|
34
|
-
super(undefined, __optsWithID("resolve"));
|
|
35
|
-
this.fail = opts.fail;
|
|
36
|
-
}
|
|
37
|
-
next(x) {
|
|
38
|
-
this.outstanding++;
|
|
39
|
-
x.then((y) => {
|
|
40
|
-
if (this.state < State.DONE) {
|
|
41
|
-
this.dispatch(y);
|
|
42
|
-
if (--this.outstanding === 0) {
|
|
43
|
-
this.done();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
LOGGER.warn(`resolved value in state ${this.state} (${x})`);
|
|
48
|
-
}
|
|
49
|
-
}, (e) => {
|
|
50
|
-
if (this.fail) {
|
|
51
|
-
this.fail(e);
|
|
52
|
-
}
|
|
53
|
-
else {
|
|
54
|
-
this.error(e);
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
done() {
|
|
59
|
-
if (this.parent &&
|
|
60
|
-
this.parent.getState() === State.DONE &&
|
|
61
|
-
this.outstanding === 0) {
|
|
62
|
-
super.done();
|
|
5
|
+
const resolve = (opts) => new Resolver(opts);
|
|
6
|
+
class Resolver extends Subscription {
|
|
7
|
+
outstanding = 0;
|
|
8
|
+
fail;
|
|
9
|
+
constructor(opts = {}) {
|
|
10
|
+
super(void 0, __optsWithID("resolve"));
|
|
11
|
+
this.fail = opts.fail;
|
|
12
|
+
}
|
|
13
|
+
next(x) {
|
|
14
|
+
this.outstanding++;
|
|
15
|
+
x.then(
|
|
16
|
+
(y) => {
|
|
17
|
+
if (this.state < State.DONE) {
|
|
18
|
+
this.dispatch(y);
|
|
19
|
+
if (--this.outstanding === 0) {
|
|
20
|
+
this.done();
|
|
21
|
+
}
|
|
22
|
+
} else {
|
|
23
|
+
LOGGER.warn(`resolved value in state ${this.state} (${x})`);
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
(e) => {
|
|
27
|
+
if (this.fail) {
|
|
28
|
+
this.fail(e);
|
|
29
|
+
} else {
|
|
30
|
+
this.error(e);
|
|
63
31
|
}
|
|
32
|
+
}
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
done() {
|
|
36
|
+
if (this.parent && this.parent.getState() === State.DONE && this.outstanding === 0) {
|
|
37
|
+
super.done();
|
|
64
38
|
}
|
|
39
|
+
}
|
|
65
40
|
}
|
|
41
|
+
export {
|
|
42
|
+
Resolver,
|
|
43
|
+
resolve
|
|
44
|
+
};
|