reactor-core-ts 3.2.2 → 3.2.4
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 +5 -0
- package/dist/core/demand.d.ts +4 -0
- package/dist/core/demand.d.ts.map +1 -1
- package/dist/core/demand.js +12 -4
- package/dist/core/demand.js.map +1 -1
- package/dist/internal/deep-value.d.ts +9 -0
- package/dist/internal/deep-value.d.ts.map +1 -0
- package/dist/internal/deep-value.js +159 -0
- package/dist/internal/deep-value.js.map +1 -0
- package/dist/internal/iterable-transform.d.ts +8 -1
- package/dist/internal/iterable-transform.d.ts.map +1 -1
- package/dist/internal/iterable-transform.js +7 -5
- package/dist/internal/iterable-transform.js.map +1 -1
- package/dist/internal/iteration-demand.d.ts +18 -0
- package/dist/internal/iteration-demand.d.ts.map +1 -0
- package/dist/internal/iteration-demand.js +34 -0
- package/dist/internal/iteration-demand.js.map +1 -0
- package/dist/internal/publisher-terminal.d.ts +25 -0
- package/dist/internal/publisher-terminal.d.ts.map +1 -0
- package/dist/internal/publisher-terminal.js +128 -0
- package/dist/internal/publisher-terminal.js.map +1 -0
- package/dist/publisher/flux.d.ts.map +1 -1
- package/dist/publisher/flux.js +22 -12
- package/dist/publisher/flux.js.map +1 -1
- package/dist/publisher/mono.d.ts.map +1 -1
- package/dist/publisher/mono.js +2 -1
- package/dist/publisher/mono.js.map +1 -1
- package/dist/publisher/operators/aggregate.d.ts.map +1 -1
- package/dist/publisher/operators/aggregate.js +136 -143
- package/dist/publisher/operators/aggregate.js.map +1 -1
- package/dist/publisher/operators/buffer-lift.d.ts +5 -0
- package/dist/publisher/operators/buffer-lift.d.ts.map +1 -0
- package/dist/publisher/operators/buffer-lift.js +197 -0
- package/dist/publisher/operators/buffer-lift.js.map +1 -0
- package/dist/publisher/operators/compat/flux.d.ts.map +1 -1
- package/dist/publisher/operators/compat/flux.js +86 -35
- package/dist/publisher/operators/compat/flux.js.map +1 -1
- package/dist/publisher/operators/coordination.d.ts.map +1 -1
- package/dist/publisher/operators/coordination.js +3 -4
- package/dist/publisher/operators/coordination.js.map +1 -1
- package/dist/publisher/operators/lifecycle.d.ts.map +1 -1
- package/dist/publisher/operators/lifecycle.js +64 -21
- package/dist/publisher/operators/lifecycle.js.map +1 -1
- package/dist/publisher/operators/lift.d.ts +2 -0
- package/dist/publisher/operators/lift.d.ts.map +1 -1
- package/dist/publisher/operators/lift.js +173 -3
- package/dist/publisher/operators/lift.js.map +1 -1
- package/dist/publisher/operators/selection.d.ts +5 -0
- package/dist/publisher/operators/selection.d.ts.map +1 -1
- package/dist/publisher/operators/selection.js +11 -2
- package/dist/publisher/operators/selection.js.map +1 -1
- package/dist/publisher/operators/terminal-mono.d.ts +12 -0
- package/dist/publisher/operators/terminal-mono.d.ts.map +1 -0
- package/dist/publisher/operators/terminal-mono.js +244 -0
- package/dist/publisher/operators/terminal-mono.js.map +1 -0
- package/dist/publisher/operators/terminal.d.ts.map +1 -1
- package/dist/publisher/operators/terminal.js +12 -25
- package/dist/publisher/operators/terminal.js.map +1 -1
- package/dist/publisher/operators/time.d.ts.map +1 -1
- package/dist/publisher/operators/time.js +2 -0
- package/dist/publisher/operators/time.js.map +1 -1
- package/dist/subscription/iterable-subscription.d.ts.map +1 -1
- package/dist/subscription/iterable-subscription.js +5 -2
- package/dist/subscription/iterable-subscription.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/iterable-terminal.d.ts +0 -12
- package/dist/internal/iterable-terminal.d.ts.map +0 -1
- package/dist/internal/iterable-terminal.js +0 -49
- package/dist/internal/iterable-terminal.js.map +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import _defineProperty from "../../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
|
+
import { UNBOUNDED_DEMAND, addCap, multiplyCap, normalizeRequest } from "../../core/demand.js";
|
|
3
|
+
import { ITERATION_DEMAND_HINT, iterationDemandHint } from "../../internal/iteration-demand.js";
|
|
4
|
+
import { liftFlux, subscriberContext } from "./lift.js";
|
|
5
|
+
//#region src/publisher/operators/buffer-lift.ts
|
|
6
|
+
/** Creates a fixed-size buffer operator that scales downstream demand upstream. */
|
|
7
|
+
function liftBuffer(source, sourceFactory, size) {
|
|
8
|
+
return liftFlux(source, sourceFactory, (subscriber) => new BufferOperatorSubscriber(subscriber, size));
|
|
9
|
+
}
|
|
10
|
+
/** Subscriber that turns each requested buffer into `size` requested source values. */
|
|
11
|
+
var BufferOperatorSubscriber = class {
|
|
12
|
+
/** Creates a buffering subscriber for one downstream subscriber. */
|
|
13
|
+
constructor(actual, size) {
|
|
14
|
+
_defineProperty(this, "actual", void 0);
|
|
15
|
+
_defineProperty(this, "size", void 0);
|
|
16
|
+
_defineProperty(
|
|
17
|
+
this,
|
|
18
|
+
/** Values accumulated for the next downstream buffer. */
|
|
19
|
+
"buffer",
|
|
20
|
+
[]
|
|
21
|
+
);
|
|
22
|
+
_defineProperty(
|
|
23
|
+
this,
|
|
24
|
+
/** Active upstream subscription. */
|
|
25
|
+
"upstream",
|
|
26
|
+
void 0
|
|
27
|
+
);
|
|
28
|
+
_defineProperty(
|
|
29
|
+
this,
|
|
30
|
+
/** Outstanding downstream buffer demand. */
|
|
31
|
+
"requested",
|
|
32
|
+
0
|
|
33
|
+
);
|
|
34
|
+
_defineProperty(
|
|
35
|
+
this,
|
|
36
|
+
/** Guards synchronous upstream requests against reentrant downstream demand. */
|
|
37
|
+
"requesting",
|
|
38
|
+
false
|
|
39
|
+
);
|
|
40
|
+
_defineProperty(
|
|
41
|
+
this,
|
|
42
|
+
/** Source demand accumulated while an upstream request call is active. */
|
|
43
|
+
"missedRequested",
|
|
44
|
+
0
|
|
45
|
+
);
|
|
46
|
+
_defineProperty(
|
|
47
|
+
this,
|
|
48
|
+
/** Prevents duplicate subscriptions from replacing the active upstream. */
|
|
49
|
+
"subscribed",
|
|
50
|
+
false
|
|
51
|
+
);
|
|
52
|
+
_defineProperty(
|
|
53
|
+
this,
|
|
54
|
+
/** Guards final-buffer delivery against reentrant upstream signals. */
|
|
55
|
+
"completing",
|
|
56
|
+
false
|
|
57
|
+
);
|
|
58
|
+
_defineProperty(
|
|
59
|
+
this,
|
|
60
|
+
/** Suppresses signals after cancellation or termination. */
|
|
61
|
+
"terminated",
|
|
62
|
+
false
|
|
63
|
+
);
|
|
64
|
+
this.actual = actual;
|
|
65
|
+
this.size = size;
|
|
66
|
+
}
|
|
67
|
+
/** Stores upstream and exposes this buffer-aware subscription downstream. */
|
|
68
|
+
onSubscribe(subscription) {
|
|
69
|
+
if (this.subscribed || this.terminated) {
|
|
70
|
+
cancelSilently(subscription);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
this.subscribed = true;
|
|
74
|
+
this.upstream = subscription;
|
|
75
|
+
try {
|
|
76
|
+
this.actual.onSubscribe(this);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
this.terminated = true;
|
|
79
|
+
cancelSilently(subscription);
|
|
80
|
+
throw error;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/** Adds one source value and emits a full buffer when it reaches the configured size. */
|
|
84
|
+
onNext(value) {
|
|
85
|
+
if (this.terminated || this.completing) return;
|
|
86
|
+
this.buffer.push(value);
|
|
87
|
+
if (this.buffer.length !== this.size) return;
|
|
88
|
+
const next = this.buffer;
|
|
89
|
+
this.buffer = [];
|
|
90
|
+
this.producedOne();
|
|
91
|
+
try {
|
|
92
|
+
this.actual.onNext(next);
|
|
93
|
+
} catch (error) {
|
|
94
|
+
this.fail(error, true);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
/** Discards the partial buffer and forwards the first source failure. */
|
|
98
|
+
onError(error) {
|
|
99
|
+
this.buffer = [];
|
|
100
|
+
this.fail(error, false);
|
|
101
|
+
}
|
|
102
|
+
/** Emits a final partial buffer and then completes downstream. */
|
|
103
|
+
onComplete() {
|
|
104
|
+
if (this.terminated || this.completing) return;
|
|
105
|
+
const finalBuffer = this.buffer;
|
|
106
|
+
this.buffer = [];
|
|
107
|
+
if (finalBuffer.length > 0) {
|
|
108
|
+
this.producedOne();
|
|
109
|
+
this.completing = true;
|
|
110
|
+
try {
|
|
111
|
+
this.actual.onNext(finalBuffer);
|
|
112
|
+
} catch (error) {
|
|
113
|
+
this.completing = false;
|
|
114
|
+
if (this.terminated) return;
|
|
115
|
+
this.terminated = true;
|
|
116
|
+
this.actual.onError(error);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
this.completing = false;
|
|
120
|
+
if (this.terminated) return;
|
|
121
|
+
}
|
|
122
|
+
this.terminated = true;
|
|
123
|
+
this.actual.onComplete();
|
|
124
|
+
}
|
|
125
|
+
/** Multiplies valid downstream buffer demand before requesting the source. */
|
|
126
|
+
request(n) {
|
|
127
|
+
if (this.terminated || this.completing) return;
|
|
128
|
+
let demand;
|
|
129
|
+
try {
|
|
130
|
+
demand = normalizeRequest(n);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
this.fail(error, true);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.requested = addCap(this.requested, demand);
|
|
136
|
+
this.requestUpstream(multiplyCap(demand, this.size));
|
|
137
|
+
}
|
|
138
|
+
/** Cancels upstream and releases buffered values. */
|
|
139
|
+
cancel() {
|
|
140
|
+
if (this.terminated) return;
|
|
141
|
+
this.terminated = true;
|
|
142
|
+
this.buffer = [];
|
|
143
|
+
this.upstream?.cancel();
|
|
144
|
+
}
|
|
145
|
+
/** Exposes downstream context unchanged. */
|
|
146
|
+
currentContext() {
|
|
147
|
+
return subscriberContext(this.actual);
|
|
148
|
+
}
|
|
149
|
+
/** Propagates a known terminal demand batch through the buffer boundary. */
|
|
150
|
+
[ITERATION_DEMAND_HINT]() {
|
|
151
|
+
const downstream = iterationDemandHint(this.actual);
|
|
152
|
+
return downstream === void 0 ? void 0 : multiplyCap(downstream, this.size);
|
|
153
|
+
}
|
|
154
|
+
/** Decrements finite downstream demand after emitting one buffer. */
|
|
155
|
+
producedOne() {
|
|
156
|
+
if (this.requested !== UNBOUNDED_DEMAND && this.requested > 0) this.requested -= 1;
|
|
157
|
+
}
|
|
158
|
+
/** Requests source demand iteratively to avoid recursive synchronous request calls. */
|
|
159
|
+
requestUpstream(demand) {
|
|
160
|
+
if (this.requesting) {
|
|
161
|
+
this.missedRequested = addCap(this.missedRequested, demand);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
this.requesting = true;
|
|
165
|
+
let request = demand;
|
|
166
|
+
try {
|
|
167
|
+
while (!this.terminated) {
|
|
168
|
+
this.upstream?.request(request);
|
|
169
|
+
if (this.terminated || this.missedRequested === 0) return;
|
|
170
|
+
request = this.missedRequested;
|
|
171
|
+
this.missedRequested = 0;
|
|
172
|
+
}
|
|
173
|
+
} catch (error) {
|
|
174
|
+
if (!this.terminated) this.fail(error, true);
|
|
175
|
+
} finally {
|
|
176
|
+
this.requesting = false;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/** Cancels when requested and forwards one terminal failure. */
|
|
180
|
+
fail(error, cancelUpstream) {
|
|
181
|
+
if (this.terminated || this.completing) return;
|
|
182
|
+
this.terminated = true;
|
|
183
|
+
this.buffer = [];
|
|
184
|
+
if (cancelUpstream && this.upstream) cancelSilently(this.upstream);
|
|
185
|
+
this.actual.onError(error);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
/** Cancels upstream without replacing the active failure or completion signal. */
|
|
189
|
+
function cancelSilently(subscription) {
|
|
190
|
+
try {
|
|
191
|
+
subscription.cancel();
|
|
192
|
+
} catch {}
|
|
193
|
+
}
|
|
194
|
+
//#endregion
|
|
195
|
+
export { liftBuffer };
|
|
196
|
+
|
|
197
|
+
//# sourceMappingURL=buffer-lift.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buffer-lift.js","names":[],"sources":["../../../src/publisher/operators/buffer-lift.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Demand-aware buffering subscriber used by fixed-size Flux buffers.\n */\nimport {Context} from \"@/context/context.js\";\nimport {addCap, multiplyCap, normalizeRequest, UNBOUNDED_DEMAND} from \"@/core/demand.js\";\nimport {ITERATION_DEMAND_HINT, iterationDemandHint} from \"@/internal/iteration-demand.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {liftFlux, subscriberContext} from \"@/publisher/operators/lift.js\";\nimport type {SourceFactory} from \"@/publisher/types.js\";\nimport type {CoreSubscriber} from \"@/subscription/core-subscriber.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Creates a fixed-size buffer operator that scales downstream demand upstream. */\nexport function liftBuffer<T>(source: Flux<T>, sourceFactory: SourceFactory<T[]>, size: number): Flux<T[]> {\n return liftFlux(source, sourceFactory, subscriber => new BufferOperatorSubscriber(subscriber, size));\n}\n\n/** Subscriber that turns each requested buffer into `size` requested source values. */\nclass BufferOperatorSubscriber<T> implements CoreSubscriber<T>, Subscription {\n /** Values accumulated for the next downstream buffer. */\n private buffer: T[] = [];\n /** Active upstream subscription. */\n private upstream: Subscription | undefined;\n /** Outstanding downstream buffer demand. */\n private requested = 0;\n /** Guards synchronous upstream requests against reentrant downstream demand. */\n private requesting = false;\n /** Source demand accumulated while an upstream request call is active. */\n private missedRequested = 0;\n /** Prevents duplicate subscriptions from replacing the active upstream. */\n private subscribed = false;\n /** Guards final-buffer delivery against reentrant upstream signals. */\n private completing = false;\n /** Suppresses signals after cancellation or termination. */\n private terminated = false;\n\n /** Creates a buffering subscriber for one downstream subscriber. */\n public constructor(private readonly actual: Subscriber<T[]>, private readonly size: number) {\n }\n\n /** Stores upstream and exposes this buffer-aware subscription downstream. */\n public onSubscribe(subscription: Subscription): void {\n if (this.subscribed || this.terminated) {\n cancelSilently(subscription);\n return;\n }\n this.subscribed = true;\n this.upstream = subscription;\n try {\n this.actual.onSubscribe(this);\n } catch (error) {\n this.terminated = true;\n cancelSilently(subscription);\n throw error;\n }\n }\n\n /** Adds one source value and emits a full buffer when it reaches the configured size. */\n public onNext(value: T): void {\n if (this.terminated || this.completing) {\n return;\n }\n this.buffer.push(value);\n if (this.buffer.length !== this.size) {\n return;\n }\n const next = this.buffer;\n this.buffer = [];\n this.producedOne();\n try {\n this.actual.onNext(next);\n } catch (error) {\n this.fail(error, true);\n }\n }\n\n /** Discards the partial buffer and forwards the first source failure. */\n public onError(error: unknown): void {\n this.buffer = [];\n this.fail(error, false);\n }\n\n /** Emits a final partial buffer and then completes downstream. */\n public onComplete(): void {\n if (this.terminated || this.completing) {\n return;\n }\n const finalBuffer = this.buffer;\n this.buffer = [];\n if (finalBuffer.length > 0) {\n this.producedOne();\n this.completing = true;\n try {\n this.actual.onNext(finalBuffer);\n } catch (error) {\n this.completing = false;\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.actual.onError(error);\n return;\n }\n this.completing = false;\n if (this.terminated) {\n return;\n }\n }\n this.terminated = true;\n this.actual.onComplete();\n }\n\n /** Multiplies valid downstream buffer demand before requesting the source. */\n public request(n: number): void {\n if (this.terminated || this.completing) {\n return;\n }\n let demand: number;\n try {\n demand = normalizeRequest(n);\n } catch (error) {\n this.fail(error, true);\n return;\n }\n this.requested = addCap(this.requested, demand);\n this.requestUpstream(multiplyCap(demand, this.size));\n }\n\n /** Cancels upstream and releases buffered values. */\n public cancel(): void {\n if (this.terminated) {\n return;\n }\n this.terminated = true;\n this.buffer = [];\n this.upstream?.cancel();\n }\n\n /** Exposes downstream context unchanged. */\n public currentContext(): Context {\n return subscriberContext(this.actual);\n }\n\n /** Propagates a known terminal demand batch through the buffer boundary. */\n public [ITERATION_DEMAND_HINT](): number | undefined {\n const downstream = iterationDemandHint(this.actual);\n return downstream === undefined ? undefined : multiplyCap(downstream, this.size);\n }\n\n /** Decrements finite downstream demand after emitting one buffer. */\n private producedOne(): void {\n if (this.requested !== UNBOUNDED_DEMAND && this.requested > 0) {\n this.requested -= 1;\n }\n }\n\n /** Requests source demand iteratively to avoid recursive synchronous request calls. */\n private requestUpstream(demand: number): void {\n if (this.requesting) {\n this.missedRequested = addCap(this.missedRequested, demand);\n return;\n }\n this.requesting = true;\n let request = demand;\n try {\n while (!this.terminated) {\n this.upstream?.request(request);\n if (this.terminated || this.missedRequested === 0) {\n return;\n }\n request = this.missedRequested;\n this.missedRequested = 0;\n }\n } catch (error) {\n if (!this.terminated) {\n this.fail(error, true);\n }\n } finally {\n this.requesting = false;\n }\n }\n\n /** Cancels when requested and forwards one terminal failure. */\n private fail(error: unknown, cancelUpstream: boolean): void {\n if (this.terminated || this.completing) {\n return;\n }\n this.terminated = true;\n this.buffer = [];\n if (cancelUpstream && this.upstream) {\n cancelSilently(this.upstream);\n }\n this.actual.onError(error);\n }\n}\n\n/** Cancels upstream without replacing the active failure or completion signal. */\nfunction cancelSilently(subscription: Subscription): void {\n try {\n subscription.cancel();\n } catch {\n // The selected terminal signal wins over cancellation failures.\n }\n}\n"],"mappings":";;;;;;AAeA,SAAgB,WAAc,QAAiB,eAAmC,MAAyB;CACvG,OAAO,SAAS,QAAQ,gBAAe,eAAc,IAAI,yBAAyB,YAAY,IAAI,CAAC;AACvG;;AAGA,IAAM,2BAAN,MAA6E;;CAmBzE,YAAmB,QAA0C,MAA+B;wBAAxD,UAAA,KAAA,CAAA;wBAA0C,QAAA,KAAA,CAAA;;;;GAjB9E;GAAsB,CAAC;;;;;GAEvB;;;;;;GAEA;GAAoB;;;;;GAEpB;GAAqB;;;;;GAErB;GAA0B;;;;;GAE1B;GAAqB;;;;;GAErB;GAAqB;;;;;GAErB;GAAqB;;EAGe,KAAA,SAAA;EAA0C,KAAA,OAAA;CAC9E;;CAGA,YAAmB,cAAkC;EACjD,IAAI,KAAK,cAAc,KAAK,YAAY;GACpC,eAAe,YAAY;GAC3B;EACJ;EACA,KAAK,aAAa;EAClB,KAAK,WAAW;EAChB,IAAI;GACA,KAAK,OAAO,YAAY,IAAI;EAChC,SAAS,OAAO;GACZ,KAAK,aAAa;GAClB,eAAe,YAAY;GAC3B,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kB,KAAK,MAAM;CACxC;;CAGA,CAAQ,yBAA6C;EACjD,MAAM,aAAa,oBAAoB,KAAK,MAAM;EAClD,OAAO,eAAe,SAAY,SAAY,YAAY,YAAY,KAAK,IAAI;CACnF;;CAGA,cAA4B;EACxB,IAAI,KAAK,cAAc,oBAAoB,KAAK,YAAY,GACxD,KAAK,aAAa;CAE1B;;CAGA,gBAAwB,QAAsB;EAC1C,IAAI,KAAK,YAAY;GACjB,KAAK,kBAAkB,OAAO,KAAK,iBAAiB,MAAM;GAC1D;EACJ;EACA,KAAK,aAAa;EAClB,IAAI,UAAU;EACd,IAAI;GACA,OAAO,CAAC,KAAK,YAAY;IACrB,KAAK,UAAU,QAAQ,OAAO;IAC9B,IAAI,KAAK,cAAc,KAAK,oBAAoB,GAC5C;IAEJ,UAAU,KAAK;IACf,KAAK,kBAAkB;GAC3B;EACJ,SAAS,OAAO;GACZ,IAAI,CAAC,KAAK,YACN,KAAK,KAAK,OAAO,IAAI;EAE7B,UAAU;GACN,KAAK,aAAa;EACtB;CACJ;;CAGA,KAAa,OAAgB,gBAA+B;EACxD,IAAI,KAAK,cAAc,KAAK,YACxB;EAEJ,KAAK,aAAa;EAClB,KAAK,SAAS,CAAC;EACf,IAAI,kBAAkB,KAAK,UACvB,eAAe,KAAK,QAAQ;EAEhC,KAAK,OAAO,QAAQ,KAAK;CAC7B;AACJ;;AAGA,SAAS,eAAe,cAAkC;CACtD,IAAI;EACA,aAAa,OAAO;CACxB,QAAQ,CAER;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flux.d.ts","sourceRoot":"","sources":["../../../../src/publisher/operators/compat/flux.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"flux.d.ts","sourceRoot":"","sources":["../../../../src/publisher/operators/compat/flux.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAGzC,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,sB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EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEtF,kDAAkD;QAClD,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE7B,6EAA6E;QAC7E,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE1D,mFAAmF;QACnF,aAAa,CAAC,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QAEzD,kEAAkE;QAClE,QAAQ,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAE7B,6EAA6E;QAC7E,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;KACzD;CACJ"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UNBOUNDED_DEMAND } from "../../../core/demand.js";
|
|
2
2
|
import { NoSuchElementError } from "../../../errors/classes.js";
|
|
3
|
+
import { consumePublisher } from "../../../internal/publisher-terminal.js";
|
|
3
4
|
import { identity } from "../../helpers.js";
|
|
4
5
|
import { Flux } from "../../flux.js";
|
|
5
|
-
import {
|
|
6
|
+
import { liftOneToOne } from "../lift.js";
|
|
7
|
+
import { terminalMono } from "../terminal-mono.js";
|
|
6
8
|
//#region src/publisher/operators/compat/flux.ts
|
|
7
9
|
/**
|
|
8
10
|
* @packageDocumentation
|
|
@@ -18,19 +20,16 @@ Flux.prototype.blockLast = function blockLast() {
|
|
|
18
20
|
return this.toPromise();
|
|
19
21
|
};
|
|
20
22
|
Flux.prototype.collect = function collect(supplier, accumulator) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
for (const value of values) accumulator(container, value);
|
|
32
|
-
yield container;
|
|
33
|
-
})();
|
|
23
|
+
return terminalMono(this, UNBOUNDED_DEMAND, () => {
|
|
24
|
+
const container = supplier();
|
|
25
|
+
return {
|
|
26
|
+
/** Accumulates one value into the supplied container. */
|
|
27
|
+
onNext(value) {
|
|
28
|
+
accumulator(container, value);
|
|
29
|
+
return false;
|
|
30
|
+
},
|
|
31
|
+
result: () => container
|
|
32
|
+
};
|
|
34
33
|
});
|
|
35
34
|
};
|
|
36
35
|
Flux.prototype.collectMap = function collectMap(keyExtractor, valueExtractor = identity) {
|
|
@@ -53,31 +52,69 @@ Flux.prototype.concatWithValues = function concatWithValues(...values) {
|
|
|
53
52
|
Flux.prototype.elementAt = function elementAt(index, defaultValue) {
|
|
54
53
|
if (!Number.isInteger(index) || index < 0) throw new RangeError("index must be a non-negative integer");
|
|
55
54
|
const hasDefault = arguments.length > 1;
|
|
56
|
-
return this
|
|
55
|
+
return terminalMono(this, index + 1, () => {
|
|
56
|
+
let remaining = index;
|
|
57
|
+
let result;
|
|
58
|
+
let found = false;
|
|
59
|
+
return {
|
|
60
|
+
/** Skips values until the requested index is reached. */
|
|
61
|
+
onNext(value) {
|
|
62
|
+
if (remaining > 0) {
|
|
63
|
+
remaining -= 1;
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
result = value;
|
|
67
|
+
found = true;
|
|
68
|
+
return true;
|
|
69
|
+
},
|
|
70
|
+
/** Resolves the indexed value, default, or missing-value error. */
|
|
71
|
+
result() {
|
|
72
|
+
if (found) return result;
|
|
73
|
+
if (hasDefault) return defaultValue;
|
|
74
|
+
throw new NoSuchElementError();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
});
|
|
57
78
|
};
|
|
58
79
|
Flux.prototype.hasElements = function hasElements() {
|
|
59
|
-
return this
|
|
80
|
+
return terminalMono(this, 1, () => {
|
|
81
|
+
let present = false;
|
|
82
|
+
return {
|
|
83
|
+
/** Marks the source as non-empty and finishes. */
|
|
84
|
+
onNext() {
|
|
85
|
+
present = true;
|
|
86
|
+
return true;
|
|
87
|
+
},
|
|
88
|
+
result: () => present
|
|
89
|
+
};
|
|
90
|
+
});
|
|
60
91
|
};
|
|
61
92
|
Flux.prototype.hide = function hide() {
|
|
62
93
|
const source = this;
|
|
63
|
-
return
|
|
94
|
+
return liftOneToOne(source, (signal, context) => source.iterate(signal, context), () => ({ onNext: identity }));
|
|
64
95
|
};
|
|
65
96
|
Flux.prototype.ignoreElements = function ignoreElements() {
|
|
66
97
|
return this.then();
|
|
67
98
|
};
|
|
68
99
|
Flux.prototype.last = function last(defaultValue) {
|
|
69
|
-
const source = this;
|
|
70
100
|
const hasDefault = arguments.length > 0;
|
|
71
|
-
return
|
|
101
|
+
return terminalMono(this, UNBOUNDED_DEMAND, () => {
|
|
72
102
|
let seen = false;
|
|
73
103
|
let lastValue;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
104
|
+
return {
|
|
105
|
+
/** Retains the latest source value. */
|
|
106
|
+
onNext(value) {
|
|
107
|
+
seen = true;
|
|
108
|
+
lastValue = value;
|
|
109
|
+
return false;
|
|
110
|
+
},
|
|
111
|
+
/** Resolves the last value, default, or empty-source error. */
|
|
112
|
+
result() {
|
|
113
|
+
if (seen) return lastValue;
|
|
114
|
+
if (hasDefault) return defaultValue;
|
|
115
|
+
throw new NoSuchElementError();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
81
118
|
});
|
|
82
119
|
};
|
|
83
120
|
Flux.prototype.mapNotNull = function mapNotNull(mapper) {
|
|
@@ -90,9 +127,16 @@ Flux.prototype.ofType = function ofType(type) {
|
|
|
90
127
|
return this.filter((value) => value instanceof type).cast();
|
|
91
128
|
};
|
|
92
129
|
Flux.prototype.reduceWith = function reduceWith(supplier, accumulator) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
130
|
+
return terminalMono(this, UNBOUNDED_DEMAND, () => {
|
|
131
|
+
let current = supplier();
|
|
132
|
+
return {
|
|
133
|
+
/** Folds one value into the supplied initial state. */
|
|
134
|
+
onNext(value) {
|
|
135
|
+
current = accumulator(current, value);
|
|
136
|
+
return false;
|
|
137
|
+
},
|
|
138
|
+
result: () => current
|
|
139
|
+
};
|
|
96
140
|
});
|
|
97
141
|
};
|
|
98
142
|
Flux.prototype.scanWith = function scanWith(supplier, accumulator) {
|
|
@@ -137,11 +181,18 @@ Flux.prototype.takeLast = function takeLast(n) {
|
|
|
137
181
|
return new Flux(async function* (signal, context) {
|
|
138
182
|
const values = [];
|
|
139
183
|
let head = 0;
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
184
|
+
await consumePublisher(source, signal, context, UNBOUNDED_DEMAND, {
|
|
185
|
+
/** Stores one value in the bounded trailing ring. */
|
|
186
|
+
onNext(value) {
|
|
187
|
+
if (values.length < n) values.push(value);
|
|
188
|
+
else {
|
|
189
|
+
values[head] = value;
|
|
190
|
+
head = (head + 1) % n;
|
|
191
|
+
}
|
|
192
|
+
return false;
|
|
193
|
+
},
|
|
194
|
+
result: () => void 0
|
|
195
|
+
});
|
|
145
196
|
for (let index = 0; index < values.length; index += 1) {
|
|
146
197
|
if (signal.aborted) return;
|
|
147
198
|
yield values[(head + index) % values.length];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flux.js","names":[],"sources":["../../../../src/publisher/operators/compat/flux.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {NoSuchElementError} from \"@/errors/classes.js\";\nimport {isAsyncIterable} from \"@/internal/iterable.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {identity} from \"@/publisher/helpers.js\";\nimport {Mono} from \"@/publisher/mono.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\n\n/** Constructor-like runtime value used by `ofType`. */\ntype ClassLike<R> = abstract new (...args: never[]) => R;\n\ndeclare module \"@/publisher/flux.js\" {\n /** Reactor compatibility operators added to Flux. */\n interface Flux<T> {\n /** Passes this Flux to a transformer and returns the transformer's result. */\n as<R>(transformer: (source: Flux<T>) => R): R;\n\n /** Resolves with the first value, or undefined when the source completes empty. */\n blockFirst(): Promise<T | undefined>;\n\n /** Resolves with the last value, or undefined when the source completes empty. */\n blockLast(): Promise<T | undefined>;\n\n /** Creates a container per subscription and accumulates every source value into it. */\n collect<R>(supplier: () => R, accumulator: (container: R, value: T) => void): Mono<R>;\n\n /** Collects source values into a Map using extracted keys and optional mapped values. */\n collectMap<K, V = T>(keyExtractor: (value: T) => K, valueExtractor?: (value: T) => V): Mono<Map<K, V>>;\n\n /** Collects source values into a Map whose keys point to arrays of matching values. */\n collectMultimap<K, V = T>(keyExtractor: (value: T) => K, valueExtractor?: (value: T) => V): Mono<Map<K, V[]>>;\n\n /** Collects all source values into an array and sorts it before emitting. */\n collectSortedList(comparator?: (left: T, right: T) => number): Mono<T[]>;\n\n /** Appends literal values after this Flux completes. */\n concatWithValues(...values: readonly T[]): Flux<T>;\n\n /** Emits the value at a zero-based index, a default, or an error when missing. */\n elementAt(index: number, defaultValue?: T): Mono<T>;\n\n /** Emits true when the source emits at least one value. */\n hasElements(): Mono<boolean>;\n\n /** Wraps this source in a new Flux to hide its concrete identity. */\n hide(): Flux<T>;\n\n /** Drops all values and completes when the source completes successfully. */\n ignoreElements(): Mono<void>;\n\n /** Emits the final source value, an optional default, or an error when empty. */\n last(defaultValue?: T): Mono<T>;\n\n /** Maps each value and drops null or undefined mapping results. */\n mapNotNull<R>(mapper: (value: T) => R | null | undefined): Flux<R>;\n\n /** Keeps only values that are instances of the provided runtime class. */\n ofType<R>(type: ClassLike<R>): Flux<R>;\n\n /** Creates an initial state per subscription and reduces source values into it. */\n reduceWith<R>(supplier: () => R, accumulator: (accumulated: R, value: T) => R): Mono<R>;\n\n /** Creates an initial state per subscription and emits each running accumulation. */\n scanWith<R>(supplier: () => R, accumulator: (accumulated: R, value: T) => R): Flux<R>;\n\n /** Drops the final `n` values from the source. */\n skipLast(n: number): Flux<T>;\n\n /** Collects all source values, sorts them, and replays the sorted values. */\n sort(comparator?: (left: T, right: T) => number): Flux<T>;\n\n /** Subscribes the provided subscriber and returns the same subscriber instance. */\n subscribeWith<S extends Subscriber<T>>(subscriber: S): S;\n\n /** Emits only the final `n` values after the source completes. */\n takeLast(n: number): Flux<T>;\n\n /** Waits for this source and then waits for `other`, ignoring all values. */\n thenEmpty(other: PublisherInput<unknown>): Mono<void>;\n }\n}\n\n\nFlux.prototype.as = function as<T, R>(this: Flux<T>, transformer: (source: Flux<T>) => R): R {\n return transformer(this);\n};\n\nFlux.prototype.blockFirst = function blockFirst<T>(this: Flux<T>): Promise<T | undefined> {\n return this.next().block();\n};\n\nFlux.prototype.blockLast = function blockLast<T>(this: Flux<T>): Promise<T | undefined> {\n return this.toPromise();\n};\n\nFlux.prototype.collect = function collect<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (container: R, value: T) => void\n): Mono<R> {\n const source = this;\n return new Mono((signal, context) => {\n const values = source.iterate(signal, context);\n if (isAsyncIterable<T>(values)) {\n return (async function* () {\n const container = supplier();\n for await (const value of values) {\n accumulator(container, value);\n }\n yield container;\n })();\n }\n return (function* () {\n const container = supplier();\n for (const value of values) {\n accumulator(container, value);\n }\n yield container;\n })();\n });\n};\n\nFlux.prototype.collectMap = function collectMap<T, K, V = T>(\n this: Flux<T>,\n keyExtractor: (value: T) => K,\n valueExtractor: (value: T) => V = identity as (value: T) => V\n): Mono<Map<K, V>> {\n return this.collect(\n () => new Map<K, V>(),\n (map, value) => map.set(keyExtractor(value), valueExtractor(value))\n );\n};\n\nFlux.prototype.collectMultimap = function collectMultimap<T, K, V = T>(\n this: Flux<T>,\n keyExtractor: (value: T) => K,\n valueExtractor: (value: T) => V = identity as (value: T) => V\n): Mono<Map<K, V[]>> {\n return this.collect(\n () => new Map<K, V[]>(),\n (map, value) => {\n const key = keyExtractor(value);\n const bucket = map.get(key);\n if (bucket) {\n bucket.push(valueExtractor(value));\n } else {\n map.set(key, [valueExtractor(value)]);\n }\n }\n );\n};\n\nFlux.prototype.collectSortedList = function collectSortedList<T>(\n this: Flux<T>,\n comparator?: (left: T, right: T) => number\n): Mono<T[]> {\n return this.collectList().map(values => values.sort(comparator));\n};\n\nFlux.prototype.concatWithValues = function concatWithValues<T>(this: Flux<T>, ...values: readonly T[]): Flux<T> {\n return this.concatWith(Flux.just(...values));\n};\n\nFlux.prototype.elementAt = function elementAt<T>(this: Flux<T>, index: number, defaultValue?: T): Mono<T> {\n if (!Number.isInteger(index) || index < 0) {\n throw new RangeError(\"index must be a non-negative integer\");\n }\n const hasDefault = arguments.length > 1;\n return this.skip(index).next().switchIfEmpty(hasDefault ? Mono.just(defaultValue as T) : Mono.error(new NoSuchElementError()));\n};\n\nFlux.prototype.hasElements = function hasElements<T>(this: Flux<T>): Mono<boolean> {\n return this.any(() => true);\n};\n\nFlux.prototype.hide = function hide<T>(this: Flux<T>): Flux<T> {\n const source = this;\n return new Flux((signal, context) => source.iterate(signal, context));\n};\n\nFlux.prototype.ignoreElements = function ignoreElements<T>(this: Flux<T>): Mono<void> {\n return this.then();\n};\n\nFlux.prototype.last = function last<T>(this: Flux<T>, defaultValue?: T): Mono<T> {\n const source = this;\n const hasDefault = arguments.length > 0;\n return new Mono(async function* (signal, context) {\n let seen = false;\n let lastValue: T | undefined;\n for await (const value of source.iterate(signal, context)) {\n seen = true;\n lastValue = value;\n }\n if (seen) {\n yield lastValue as T;\n } else if (hasDefault) {\n yield defaultValue as T;\n } else {\n throw new NoSuchElementError();\n }\n });\n};\n\nFlux.prototype.mapNotNull = function mapNotNull<T, R>(\n this: Flux<T>,\n mapper: (value: T) => R | null | undefined\n): Flux<R> {\n return this.handle((value, sink) => {\n const mapped = mapper(value);\n if (mapped !== null && mapped !== undefined) {\n sink.next(mapped);\n }\n });\n};\n\nFlux.prototype.ofType = function ofType<T, R>(this: Flux<T>, type: ClassLike<R>): Flux<R> {\n return this.filter(value => value instanceof type).cast<R>();\n};\n\nFlux.prototype.reduceWith = function reduceWith<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (accumulated: R, value: T) => R\n): Mono<R> {\n const source = this;\n return new Mono(async function* (signal, context) {\n for await (const value of source.reduce(supplier(), accumulator).iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.scanWith = function scanWith<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (accumulated: R, value: T) => R\n): Flux<R> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.scan(supplier(), accumulator).iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.skipLast = function skipLast<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"skipLast expects a non-negative integer\");\n }\n if (n === 0) {\n return this;\n }\n const source = this;\n return new Flux(async function* (signal, context) {\n const queue: T[] = [];\n let head = 0;\n for await (const value of source.iterate(signal, context)) {\n queue.push(value);\n if (queue.length - head > n) {\n const next = queue[head] as T;\n head += 1;\n if (head > 1024 && head * 2 > queue.length) {\n queue.copyWithin(0, head);\n queue.length -= head;\n head = 0;\n }\n yield next;\n }\n }\n });\n};\n\nFlux.prototype.sort = function sort<T>(this: Flux<T>, comparator?: (left: T, right: T) => number): Flux<T> {\n return new Flux((signal, context) => this.collectSortedList(comparator).flatMapMany(Flux.fromIterable).iterate(signal, context));\n};\n\nFlux.prototype.subscribeWith = function subscribeWith<T, S extends Subscriber<T>>(this: Flux<T>, subscriber: S): S {\n this.subscribe(subscriber);\n return subscriber;\n};\n\nFlux.prototype.takeLast = function takeLast<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"takeLast expects a non-negative integer\");\n }\n if (n === 0) {\n return Flux.empty<T>();\n }\n const source = this;\n return new Flux(async function* (signal, context) {\n const values: T[] = [];\n let head = 0;\n for await (const value of source.iterate(signal, context)) {\n if (values.length < n) {\n values.push(value);\n } else {\n values[head] = value;\n head = (head + 1) % n;\n }\n }\n for (let index = 0; index < values.length; index += 1) {\n if (signal.aborted) {\n return;\n }\n yield values[(head + index) % values.length] as T;\n }\n });\n};\n\nFlux.prototype.thenEmpty = function thenEmpty<T>(this: Flux<T>, other: PublisherInput<unknown>): Mono<void> {\n return this.thenMany(other).then();\n};\n"],"mappings":";;;;;;;;;;AAuFA,KAAK,UAAU,KAAK,SAAS,GAAwB,aAAwC;CACzF,OAAO,YAAY,IAAI;AAC3B;AAEA,KAAK,UAAU,aAAa,SAAS,aAAqD;CACtF,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM;AAC7B;AAEA,KAAK,UAAU,YAAY,SAAS,YAAoD;CACpF,OAAO,KAAK,UAAU;AAC1B;AAEA,KAAK,UAAU,UAAU,SAAS,QAE9B,UACA,aACO;CACP,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY;EACjC,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO;EAC7C,IAAI,gBAAmB,MAAM,GACzB,QAAQ,mBAAmB;GACvB,MAAM,YAAY,SAAS;GAC3B,WAAW,MAAM,SAAS,QACtB,YAAY,WAAW,KAAK;GAEhC,MAAM;EACV,EAAA,CAAG;EAEP,QAAQ,aAAa;GACjB,MAAM,YAAY,SAAS;GAC3B,KAAK,MAAM,SAAS,QAChB,YAAY,WAAW,KAAK;GAEhC,MAAM;EACV,EAAA,CAAG;CACP,CAAC;AACL;AAEA,KAAK,UAAU,aAAa,SAAS,WAEjC,cACA,iBAAkC,UACnB;CACf,OAAO,KAAK,8BACF,IAAI,IAAU,IACnB,KAAK,UAAU,IAAI,IAAI,aAAa,KAAK,GAAG,eAAe,KAAK,CAAC,CACtE;AACJ;A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,CAAC,CAAC,KAAK;AACrC"}
|
|
1
|
+
{"version":3,"file":"flux.js","names":[],"sources":["../../../../src/publisher/operators/compat/flux.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {UNBOUNDED_DEMAND} from \"@/core/demand.js\";\nimport {NoSuchElementError} from \"@/errors/classes.js\";\nimport {consumePublisher} from \"@/internal/publisher-terminal.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {identity} from \"@/publisher/helpers.js\";\nimport {Mono} from \"@/publisher/mono.js\";\nimport {liftOneToOne} from \"@/publisher/operators/lift.js\";\nimport {terminalMono} from \"@/publisher/operators/terminal-mono.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\n\n/** Constructor-like runtime value used by `ofType`. */\ntype ClassLike<R> = abstract new (...args: never[]) => R;\n\ndeclare module \"@/publisher/flux.js\" {\n /** Reactor compatibility operators added to Flux. */\n interface Flux<T> {\n /** Passes this Flux to a transformer and returns the transformer's result. */\n as<R>(transformer: (source: Flux<T>) => R): R;\n\n /** Resolves with the first value, or undefined when the source completes empty. */\n blockFirst(): Promise<T | undefined>;\n\n /** Resolves with the last value, or undefined when the source completes empty. */\n blockLast(): Promise<T | undefined>;\n\n /** Creates a container per subscription and accumulates every source value into it. */\n collect<R>(supplier: () => R, accumulator: (container: R, value: T) => void): Mono<R>;\n\n /** Collects source values into a Map using extracted keys and optional mapped values. */\n collectMap<K, V = T>(keyExtractor: (value: T) => K, valueExtractor?: (value: T) => V): Mono<Map<K, V>>;\n\n /** Collects source values into a Map whose keys point to arrays of matching values. */\n collectMultimap<K, V = T>(keyExtractor: (value: T) => K, valueExtractor?: (value: T) => V): Mono<Map<K, V[]>>;\n\n /** Collects all source values into an array and sorts it before emitting. */\n collectSortedList(comparator?: (left: T, right: T) => number): Mono<T[]>;\n\n /** Appends literal values after this Flux completes. */\n concatWithValues(...values: readonly T[]): Flux<T>;\n\n /** Emits the value at a zero-based index, a default, or an error when missing. */\n elementAt(index: number, defaultValue?: T): Mono<T>;\n\n /** Emits true when the source emits at least one value. */\n hasElements(): Mono<boolean>;\n\n /** Wraps this source in a new Flux to hide its concrete identity. */\n hide(): Flux<T>;\n\n /** Drops all values and completes when the source completes successfully. */\n ignoreElements(): Mono<void>;\n\n /** Emits the final source value, an optional default, or an error when empty. */\n last(defaultValue?: T): Mono<T>;\n\n /** Maps each value and drops null or undefined mapping results. */\n mapNotNull<R>(mapper: (value: T) => R | null | undefined): Flux<R>;\n\n /** Keeps only values that are instances of the provided runtime class. */\n ofType<R>(type: ClassLike<R>): Flux<R>;\n\n /** Creates an initial state per subscription and reduces source values into it. */\n reduceWith<R>(supplier: () => R, accumulator: (accumulated: R, value: T) => R): Mono<R>;\n\n /** Creates an initial state per subscription and emits each running accumulation. */\n scanWith<R>(supplier: () => R, accumulator: (accumulated: R, value: T) => R): Flux<R>;\n\n /** Drops the final `n` values from the source. */\n skipLast(n: number): Flux<T>;\n\n /** Collects all source values, sorts them, and replays the sorted values. */\n sort(comparator?: (left: T, right: T) => number): Flux<T>;\n\n /** Subscribes the provided subscriber and returns the same subscriber instance. */\n subscribeWith<S extends Subscriber<T>>(subscriber: S): S;\n\n /** Emits only the final `n` values after the source completes. */\n takeLast(n: number): Flux<T>;\n\n /** Waits for this source and then waits for `other`, ignoring all values. */\n thenEmpty(other: PublisherInput<unknown>): Mono<void>;\n }\n}\n\n\nFlux.prototype.as = function as<T, R>(this: Flux<T>, transformer: (source: Flux<T>) => R): R {\n return transformer(this);\n};\n\nFlux.prototype.blockFirst = function blockFirst<T>(this: Flux<T>): Promise<T | undefined> {\n return this.next().block();\n};\n\nFlux.prototype.blockLast = function blockLast<T>(this: Flux<T>): Promise<T | undefined> {\n return this.toPromise();\n};\n\nFlux.prototype.collect = function collect<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (container: R, value: T) => void\n): Mono<R> {\n return terminalMono(this, UNBOUNDED_DEMAND, () => {\n const container = supplier();\n return {\n /** Accumulates one value into the supplied container. */\n onNext(value) {\n accumulator(container, value);\n return false;\n },\n result: () => container\n };\n });\n};\n\nFlux.prototype.collectMap = function collectMap<T, K, V = T>(\n this: Flux<T>,\n keyExtractor: (value: T) => K,\n valueExtractor: (value: T) => V = identity as (value: T) => V\n): Mono<Map<K, V>> {\n return this.collect(\n () => new Map<K, V>(),\n (map, value) => map.set(keyExtractor(value), valueExtractor(value))\n );\n};\n\nFlux.prototype.collectMultimap = function collectMultimap<T, K, V = T>(\n this: Flux<T>,\n keyExtractor: (value: T) => K,\n valueExtractor: (value: T) => V = identity as (value: T) => V\n): Mono<Map<K, V[]>> {\n return this.collect(\n () => new Map<K, V[]>(),\n (map, value) => {\n const key = keyExtractor(value);\n const bucket = map.get(key);\n if (bucket) {\n bucket.push(valueExtractor(value));\n } else {\n map.set(key, [valueExtractor(value)]);\n }\n }\n );\n};\n\nFlux.prototype.collectSortedList = function collectSortedList<T>(\n this: Flux<T>,\n comparator?: (left: T, right: T) => number\n): Mono<T[]> {\n return this.collectList().map(values => values.sort(comparator));\n};\n\nFlux.prototype.concatWithValues = function concatWithValues<T>(this: Flux<T>, ...values: readonly T[]): Flux<T> {\n return this.concatWith(Flux.just(...values));\n};\n\nFlux.prototype.elementAt = function elementAt<T>(this: Flux<T>, index: number, defaultValue?: T): Mono<T> {\n if (!Number.isInteger(index) || index < 0) {\n throw new RangeError(\"index must be a non-negative integer\");\n }\n const hasDefault = arguments.length > 1;\n return terminalMono<T, T>(this, index + 1, () => {\n let remaining = index;\n let result: T | undefined;\n let found = false;\n return {\n /** Skips values until the requested index is reached. */\n onNext(value) {\n if (remaining > 0) {\n remaining -= 1;\n return false;\n }\n result = value;\n found = true;\n return true;\n },\n /** Resolves the indexed value, default, or missing-value error. */\n result() {\n if (found) {\n return result as T;\n }\n if (hasDefault) {\n return defaultValue as T;\n }\n throw new NoSuchElementError();\n }\n };\n });\n};\n\nFlux.prototype.hasElements = function hasElements<T>(this: Flux<T>): Mono<boolean> {\n return terminalMono(this, 1, () => {\n let present = false;\n return {\n /** Marks the source as non-empty and finishes. */\n onNext() {\n present = true;\n return true;\n },\n result: () => present\n };\n });\n};\n\nFlux.prototype.hide = function hide<T>(this: Flux<T>): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => source.iterate(signal, context),\n () => ({onNext: identity})\n );\n};\n\nFlux.prototype.ignoreElements = function ignoreElements<T>(this: Flux<T>): Mono<void> {\n return this.then();\n};\n\nFlux.prototype.last = function last<T>(this: Flux<T>, defaultValue?: T): Mono<T> {\n const hasDefault = arguments.length > 0;\n return terminalMono(this, UNBOUNDED_DEMAND, () => {\n let seen = false;\n let lastValue: T | undefined;\n return {\n /** Retains the latest source value. */\n onNext(value) {\n seen = true;\n lastValue = value;\n return false;\n },\n /** Resolves the last value, default, or empty-source error. */\n result() {\n if (seen) {\n return lastValue as T;\n }\n if (hasDefault) {\n return defaultValue as T;\n }\n throw new NoSuchElementError();\n }\n };\n });\n};\n\nFlux.prototype.mapNotNull = function mapNotNull<T, R>(\n this: Flux<T>,\n mapper: (value: T) => R | null | undefined\n): Flux<R> {\n return this.handle((value, sink) => {\n const mapped = mapper(value);\n if (mapped !== null && mapped !== undefined) {\n sink.next(mapped);\n }\n });\n};\n\nFlux.prototype.ofType = function ofType<T, R>(this: Flux<T>, type: ClassLike<R>): Flux<R> {\n return this.filter(value => value instanceof type).cast<R>();\n};\n\nFlux.prototype.reduceWith = function reduceWith<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (accumulated: R, value: T) => R\n): Mono<R> {\n return terminalMono(this, UNBOUNDED_DEMAND, () => {\n let current = supplier();\n return {\n /** Folds one value into the supplied initial state. */\n onNext(value) {\n current = accumulator(current, value);\n return false;\n },\n result: () => current\n };\n });\n};\n\nFlux.prototype.scanWith = function scanWith<T, R>(\n this: Flux<T>,\n supplier: () => R,\n accumulator: (accumulated: R, value: T) => R\n): Flux<R> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.scan(supplier(), accumulator).iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.skipLast = function skipLast<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"skipLast expects a non-negative integer\");\n }\n if (n === 0) {\n return this;\n }\n const source = this;\n return new Flux(async function* (signal, context) {\n const queue: T[] = [];\n let head = 0;\n for await (const value of source.iterate(signal, context)) {\n queue.push(value);\n if (queue.length - head > n) {\n const next = queue[head] as T;\n head += 1;\n if (head > 1024 && head * 2 > queue.length) {\n queue.copyWithin(0, head);\n queue.length -= head;\n head = 0;\n }\n yield next;\n }\n }\n });\n};\n\nFlux.prototype.sort = function sort<T>(this: Flux<T>, comparator?: (left: T, right: T) => number): Flux<T> {\n return new Flux((signal, context) => this.collectSortedList(comparator).flatMapMany(Flux.fromIterable).iterate(signal, context));\n};\n\nFlux.prototype.subscribeWith = function subscribeWith<T, S extends Subscriber<T>>(this: Flux<T>, subscriber: S): S {\n this.subscribe(subscriber);\n return subscriber;\n};\n\nFlux.prototype.takeLast = function takeLast<T>(this: Flux<T>, n: number): Flux<T> {\n if (!Number.isInteger(n) || n < 0) {\n throw new RangeError(\"takeLast expects a non-negative integer\");\n }\n if (n === 0) {\n return Flux.empty<T>();\n }\n const source = this;\n return new Flux(async function* (signal, context) {\n const values: T[] = [];\n let head = 0;\n await consumePublisher<T, void>(source, signal, context, UNBOUNDED_DEMAND, {\n /** Stores one value in the bounded trailing ring. */\n onNext(value) {\n if (values.length < n) {\n values.push(value);\n } else {\n values[head] = value;\n head = (head + 1) % n;\n }\n return false;\n },\n result: () => undefined\n });\n for (let index = 0; index < values.length; index += 1) {\n if (signal.aborted) {\n return;\n }\n yield values[(head + index) % values.length] as T;\n }\n });\n};\n\nFlux.prototype.thenEmpty = function thenEmpty<T>(this: Flux<T>, other: PublisherInput<unknown>): Mono<void> {\n return this.thenMany(other).then();\n};\n"],"mappings":";;;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OAAO,SAAS,KAAuB,YAAqD;CACvG,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,kBAAkB,UAAU,CAAC,CAAC,YAAY,KAAK,YAAY,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AACnI;AAEA,KAAK,UAAU,gBAAgB,SAAS,cAAyD,YAAkB;CAC/G,KAAK,UAAU,UAAU;CACzB,OAAO;AACX;AAEA,KAAK,UAAU,WAAW,SAAS,SAA2B,GAAoB;CAC9E,IAAI,CAAC,OAAO,UAAU,CAAC,KAAK,IAAI,GAC5B,MAAM,IAAI,WAAW,yCAAyC;CAElE,IAAI,MAAM,GACN,OAAO,KAAK,MAAS;CAEzB,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,MAAM,SAAc,CAAC;EACrB,IAAI,OAAO;EACX,MAAM,iBAA0B,QAAQ,QAAQ,SAAS,kBAAkB;;GAEvE,OAAO,OAAO;IACV,IAAI,OAAO,SAAS,GAChB,OAAO,KAAK,KAAK;SACd;KACH,OAAO,QAAQ;KACf,QAAQ,OAAO,KAAK;IACxB;IACA,OAAO;GACX;GACA,cAAc;EAClB,CAAC;EACD,KAAK,IAAI,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS,GAAG;GACnD,IAAI,OAAO,SACP;GAEJ,MAAM,QAAQ,OAAO,SAAS,OAAO;EACzC;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,YAAY,SAAS,UAA4B,OAA4C;CACxG,OAAO,KAAK,SAAS,KAAK,CAAC,CAAC,KAAK;AACrC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coordination.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/coordination.ts"],"names":[],"mappings":"AAOA,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"coordination.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/coordination.ts"],"names":[],"mappings":"AAOA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IAAI,CAAC,CAAC,CAAC,KAAK,cAAc,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAElG,qDAAqD;QACrD,cAAc,CAAC,KAAK,EAAE,cAAc,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAExD,oDAAoD;QACpD,KAAK,CAAC,SAAS,CAAC,EAAE,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAE7C,wEAAwE;QACxE,cAAc,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAEjH,oDAAoD;QACpD,eAAe,CAAC,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;KAC/G;CACJ"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { toAsyncIterator } from "../../internal/iterable.js";
|
|
2
2
|
import { AsyncQueue } from "../../internal/async-queue.js";
|
|
3
|
+
import { collectPublisher, drainPublisher } from "../../internal/publisher-terminal.js";
|
|
3
4
|
import { Schedulers } from "../../schedulers/schedulers.js";
|
|
4
5
|
import { scheduleDelay } from "../helpers.js";
|
|
5
6
|
import { Flux } from "../flux.js";
|
|
@@ -258,13 +259,11 @@ function delayErrors(source) {
|
|
|
258
259
|
}
|
|
259
260
|
/** Collects a finite publisher input into an array. */
|
|
260
261
|
async function collect(source, signal, context) {
|
|
261
|
-
|
|
262
|
-
for await (const value of Flux.from(source).iterate(signal, context)) values.push(value);
|
|
263
|
-
return values;
|
|
262
|
+
return collectPublisher(Flux.from(source), signal, context);
|
|
264
263
|
}
|
|
265
264
|
/** Consumes a publisher input and ignores all values. */
|
|
266
265
|
async function drain(source, signal, context) {
|
|
267
|
-
|
|
266
|
+
await drainPublisher(Flux.from(source), signal, context);
|
|
268
267
|
}
|
|
269
268
|
/** Resolves the first value from a publisher input using the current subscriber context. */
|
|
270
269
|
async function firstValueFromContext(source, signal, context) {
|