reactor-core-ts 3.2.3 → 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/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/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.map +1 -1
- package/dist/publisher/operators/selection.js +3 -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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { UNBOUNDED_DEMAND } from "../../core/demand.js";
|
|
2
|
+
import { collectPublisher, drainPublisher } from "../../internal/publisher-terminal.js";
|
|
1
3
|
import { Schedulers } from "../../schedulers/schedulers.js";
|
|
2
4
|
import { scheduleDelay } from "../helpers.js";
|
|
3
5
|
import { Flux } from "../flux.js";
|
|
@@ -10,15 +12,11 @@ Flux.prototype.cache = function cache(_ttl, _scheduler) {
|
|
|
10
12
|
let failure;
|
|
11
13
|
let loaded;
|
|
12
14
|
return new Flux(async function* (signal, context) {
|
|
13
|
-
loaded ?? (loaded = (
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
} catch (error) {
|
|
19
|
-
failure = error;
|
|
20
|
-
}
|
|
21
|
-
})());
|
|
15
|
+
loaded ?? (loaded = collectPublisher(source, signal, context).then((nextValues) => {
|
|
16
|
+
values = nextValues;
|
|
17
|
+
}, (error) => {
|
|
18
|
+
failure = error;
|
|
19
|
+
}));
|
|
22
20
|
await loaded;
|
|
23
21
|
if (failure !== void 0) throw failure;
|
|
24
22
|
yield* values ?? [];
|
|
@@ -69,7 +67,7 @@ Flux.prototype.delayUntil = function delayUntil(triggerProvider) {
|
|
|
69
67
|
};
|
|
70
68
|
Flux.prototype.doAfterTerminate = function doAfterTerminate(callback) {
|
|
71
69
|
const source = this;
|
|
72
|
-
return
|
|
70
|
+
return liftOneToOne(source, async function* (signal, context) {
|
|
73
71
|
let terminated = false;
|
|
74
72
|
try {
|
|
75
73
|
for await (const value of source.iterate(signal, context)) yield value;
|
|
@@ -77,28 +75,40 @@ Flux.prototype.doAfterTerminate = function doAfterTerminate(callback) {
|
|
|
77
75
|
} finally {
|
|
78
76
|
if (terminated) callback();
|
|
79
77
|
}
|
|
80
|
-
})
|
|
78
|
+
}, () => ({
|
|
79
|
+
onNext: passThrough,
|
|
80
|
+
/** Runs the callback after non-cancellation terminal signals. */
|
|
81
|
+
onFinally(signal) {
|
|
82
|
+
if (signal !== "cancel") callback();
|
|
83
|
+
}
|
|
84
|
+
}));
|
|
81
85
|
};
|
|
82
86
|
Flux.prototype.doFirst = function doFirst(callback) {
|
|
83
87
|
const source = this;
|
|
84
|
-
return
|
|
88
|
+
return liftOneToOne(source, (signal, context) => {
|
|
85
89
|
callback();
|
|
86
90
|
return source.iterate(signal, context);
|
|
91
|
+
}, () => {
|
|
92
|
+
callback();
|
|
93
|
+
return { onNext: passThrough };
|
|
87
94
|
});
|
|
88
95
|
};
|
|
89
96
|
Flux.prototype.doOnCancel = function doOnCancel(callback) {
|
|
90
97
|
const source = this;
|
|
91
|
-
return
|
|
98
|
+
return liftOneToOne(source, (signal, context) => {
|
|
92
99
|
signal.addEventListener("abort", callback, { once: true });
|
|
93
100
|
return source.iterate(signal, context);
|
|
94
|
-
})
|
|
101
|
+
}, () => ({
|
|
102
|
+
onNext: passThrough,
|
|
103
|
+
onCancel: callback
|
|
104
|
+
}));
|
|
95
105
|
};
|
|
96
106
|
Flux.prototype.doOnDiscard = function doOnDiscard(_type, _callback) {
|
|
97
107
|
return this;
|
|
98
108
|
};
|
|
99
109
|
Flux.prototype.doOnEach = function doOnEach(callback) {
|
|
100
110
|
const source = this;
|
|
101
|
-
return
|
|
111
|
+
return liftOneToOne(source, async function* (signal, context) {
|
|
102
112
|
try {
|
|
103
113
|
for await (const value of source.iterate(signal, context)) {
|
|
104
114
|
callback(Signal.next(value));
|
|
@@ -109,12 +119,20 @@ Flux.prototype.doOnEach = function doOnEach(callback) {
|
|
|
109
119
|
callback(Signal.error(error));
|
|
110
120
|
throw error;
|
|
111
121
|
}
|
|
112
|
-
})
|
|
122
|
+
}, () => ({
|
|
123
|
+
/** Observes one next signal and relays its value. */
|
|
124
|
+
onNext(value) {
|
|
125
|
+
callback(Signal.next(value));
|
|
126
|
+
return value;
|
|
127
|
+
},
|
|
128
|
+
onError: (error) => callback(Signal.error(error)),
|
|
129
|
+
onComplete: () => callback(Signal.complete())
|
|
130
|
+
}));
|
|
113
131
|
};
|
|
114
132
|
Flux.prototype.doOnRequest = function doOnRequest(callback) {
|
|
115
133
|
const source = this;
|
|
116
134
|
return liftOneToOne(source, (signal, context) => {
|
|
117
|
-
callback(
|
|
135
|
+
callback(UNBOUNDED_DEMAND);
|
|
118
136
|
return source.iterate(signal, context);
|
|
119
137
|
}, () => ({
|
|
120
138
|
onNext: passThrough,
|
|
@@ -133,7 +151,7 @@ Flux.prototype.doOnSubscribe = function doOnSubscribe(callback) {
|
|
|
133
151
|
};
|
|
134
152
|
Flux.prototype.doOnTerminate = function doOnTerminate(callback) {
|
|
135
153
|
const source = this;
|
|
136
|
-
return
|
|
154
|
+
return liftOneToOne(source, async function* (signal, context) {
|
|
137
155
|
try {
|
|
138
156
|
for await (const value of source.iterate(signal, context)) yield value;
|
|
139
157
|
callback();
|
|
@@ -141,7 +159,11 @@ Flux.prototype.doOnTerminate = function doOnTerminate(callback) {
|
|
|
141
159
|
callback();
|
|
142
160
|
throw error;
|
|
143
161
|
}
|
|
144
|
-
})
|
|
162
|
+
}, () => ({
|
|
163
|
+
onNext: passThrough,
|
|
164
|
+
onError: callback,
|
|
165
|
+
onComplete: callback
|
|
166
|
+
}));
|
|
145
167
|
};
|
|
146
168
|
Flux.prototype.limitRate = function limitRate(_highTide, _lowTide) {
|
|
147
169
|
return this;
|
|
@@ -212,7 +234,7 @@ Flux.prototype.tag = function tag(_key, _value) {
|
|
|
212
234
|
};
|
|
213
235
|
Flux.prototype.tap = function tap(listener) {
|
|
214
236
|
const source = this;
|
|
215
|
-
return
|
|
237
|
+
return liftOneToOne(source, async function* (signal, context) {
|
|
216
238
|
const actual = typeof listener === "function" ? listener() : listener;
|
|
217
239
|
signal.addEventListener("abort", () => actual.onCancel?.(), { once: true });
|
|
218
240
|
try {
|
|
@@ -228,6 +250,27 @@ Flux.prototype.tap = function tap(listener) {
|
|
|
228
250
|
actual.onSignal?.(Signal.error(error));
|
|
229
251
|
throw error;
|
|
230
252
|
}
|
|
253
|
+
}, () => {
|
|
254
|
+
const actual = typeof listener === "function" ? listener() : listener;
|
|
255
|
+
return {
|
|
256
|
+
/** Notifies the listener about one value and relays it. */
|
|
257
|
+
onNext(value) {
|
|
258
|
+
actual.onNext?.(value);
|
|
259
|
+
actual.onSignal?.(Signal.next(value));
|
|
260
|
+
return value;
|
|
261
|
+
},
|
|
262
|
+
/** Notifies the listener about an error signal. */
|
|
263
|
+
onError(error) {
|
|
264
|
+
actual.onError?.(error);
|
|
265
|
+
actual.onSignal?.(Signal.error(error));
|
|
266
|
+
},
|
|
267
|
+
/** Notifies the listener about successful completion. */
|
|
268
|
+
onComplete() {
|
|
269
|
+
actual.onComplete?.();
|
|
270
|
+
actual.onSignal?.(Signal.complete());
|
|
271
|
+
},
|
|
272
|
+
onCancel: () => actual.onCancel?.()
|
|
273
|
+
};
|
|
231
274
|
});
|
|
232
275
|
};
|
|
233
276
|
Flux.prototype.toStream = function toStream() {
|
|
@@ -243,7 +286,7 @@ function isPublisherLike(value) {
|
|
|
243
286
|
}
|
|
244
287
|
/** Consumes a publisher input and ignores all emitted values. */
|
|
245
288
|
async function drain(source, signal, context) {
|
|
246
|
-
|
|
289
|
+
await drainPublisher(Flux.from(source), signal, context);
|
|
247
290
|
}
|
|
248
291
|
/** Creates a no-op subscription object for doOnSubscribe callbacks. */
|
|
249
292
|
function noopSubscription() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/publisher/operators/lifecycle.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactor lifecycle, context, logging and browser backpressure compatibility operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {ContextView} from \"@/context/context-view.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {scheduleDelay} from \"@/publisher/helpers.js\";\nimport {liftOneToOne, subscriberContext} from \"@/publisher/operators/lift.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\nimport {Signal} from \"@/signal/signal.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Listener shape accepted by the lightweight `tap` compatibility operator. */\nexport interface FluxTapListener<T> {\n /** Invoked for each next value. */\n onNext?(value: T): void;\n\n /** Invoked when the sequence fails. */\n onError?(error: unknown): void;\n\n /** Invoked when the sequence completes. */\n onComplete?(): void;\n\n /** Invoked when the sequence is cancelled. */\n onCancel?(): void;\n\n /** Invoked for materialized next, error and complete signals. */\n onSignal?(signal: Signal<T>): void;\n}\n\ndeclare module \"@/publisher/flux.js\" {\n /** Lifecycle, context and browser backpressure compatibility operators added to Flux. */\n interface Flux<T> {\n /** Replays the collected source values to later subscribers. */\n cache(ttl?: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Schedules cancellation on the provided scheduler when supported by the source. */\n cancelOn(scheduler: Scheduler): Flux<T>;\n\n /** Adds an assembly checkpoint marker. Browser implementation keeps the source unchanged. */\n checkpoint(description?: string, forceStackTrace?: boolean): Flux<T>;\n\n /** Captures ambient context when an integration provides it. Browser implementation keeps the source unchanged. */\n contextCapture(): Flux<T>;\n\n /** Writes subscriber context for upstream operators. */\n contextWrite(context: ContextView | Context | ((context: Context) => Context)): Flux<T>;\n\n /** Delays subscribing to the source. */\n delaySequence(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Delays subscribing to the source by time or until another publisher signals. */\n delaySubscription(delay: DurationInput | PublisherInput<unknown>, scheduler?: Scheduler): Flux<T>;\n\n /** Delays each value until the trigger publisher derived from that value completes. */\n delayUntil(triggerProvider: (value: T) => PublisherInput<unknown>): Flux<T>;\n\n /** Invokes a callback after successful or failed termination. */\n doAfterTerminate(callback: () => void): Flux<T>;\n\n /** Invokes a callback before source iteration starts. */\n doFirst(callback: () => void): Flux<T>;\n\n /** Invokes a callback when the subscription is cancelled. */\n doOnCancel(callback: () => void): Flux<T>;\n\n /** Registers a discard hook. Browser implementation keeps values unchanged. */\n doOnDiscard<R>(type: new (...args: never[]) => R, callback: (value: R) => void): Flux<T>;\n\n /** Invokes a callback for every materialized source signal. */\n doOnEach(callback: (signal: Signal<T>) => void): Flux<T>;\n\n /** Invokes a callback when unbounded demand is requested by the async bridge. */\n doOnRequest(callback: (request: number) => void): Flux<T>;\n\n /** Invokes a callback with a synthetic subscription before source iteration starts. */\n doOnSubscribe(callback: (subscription: Subscription) => void): Flux<T>;\n\n /** Invokes a callback before successful or failed termination. */\n doOnTerminate(callback: () => void): Flux<T>;\n\n /** Keeps request batching metadata. Browser async iteration returns this source unchanged. */\n limitRate(highTide: number, lowTide?: number): Flux<T>;\n\n /** Limits the total number of requested values. */\n limitRequest(n: number): Flux<T>;\n\n /** Logs source signals to the console. */\n log(category?: string): Flux<T>;\n\n /** Keeps metrics compatibility metadata. Browser implementation returns this source unchanged. */\n metrics(): Flux<T>;\n\n /** Keeps a human-readable sequence name. Browser implementation returns this source unchanged. */\n name(name: string): Flux<T>;\n\n /** Buffers on backpressure. Browser async iteration already buffers by pull demand. */\n onBackpressureBuffer(...args: unknown[]): Flux<T>;\n\n /** Drops on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureDrop(callback?: (value: T) => void): Flux<T>;\n\n /** Fails on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureError(): Flux<T>;\n\n /** Keeps only the latest value on backpressure. Browser async iteration returns this source unchanged. */\n onBackpressureLatest(): Flux<T>;\n\n /** Completes instead of failing when the optional predicate accepts the error. */\n onErrorComplete(predicate?: (error: unknown) => boolean): Flux<T>;\n\n /** Continues with completion after invoking an error continuation callback. */\n onErrorContinue(callback: (error: unknown, value: T | undefined) => void): Flux<T>;\n\n /** Stops error continuation mode. Browser implementation returns this source unchanged. */\n onErrorStop(): Flux<T>;\n\n /** Drops terminal-reference retention hints. Browser implementation returns this source unchanged. */\n onTerminateDetach(): Flux<T>;\n\n /** Transforms a shared source or returns a shared source view. */\n publish<R = T>(transformer?: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Returns a Mono with the next value from this source. */\n publishNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Returns a replaying view of this source. */\n replay(...args: unknown[]): Flux<T>;\n\n /** Returns a shared browser view of this source. */\n share(): Flux<T>;\n\n /** Returns a Mono with the next value from a shared source. */\n shareNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Stores a metadata tag. Browser implementation returns this source unchanged. */\n tag(key: string, value: string): Flux<T>;\n\n /** Installs listener callbacks for values, terminal signals, and cancellation. */\n tap(listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T>;\n\n /** Returns an async iterator stream view of this Flux. */\n toStream(): AsyncIterable<T>;\n }\n}\n\nFlux.prototype.cache = function cache<T>(this: Flux<T>, _ttl?: DurationInput, _scheduler?: Scheduler): Flux<T> {\n const source = this;\n let values: T[] | undefined;\n let failure: unknown;\n let loaded: Promise<void> | undefined;\n return new Flux(async function* (signal, context) {\n loaded ??= (async () => {\n const nextValues: T[] = [];\n try {\n for await (const value of source.iterate(signal, context)) {\n nextValues.push(value);\n }\n values = nextValues;\n } catch (error) {\n failure = error;\n }\n })();\n await loaded;\n if (failure !== undefined) {\n throw failure;\n }\n yield* values ?? [];\n });\n};\n\nFlux.prototype.cancelOn = function cancelOn<T>(this: Flux<T>, _scheduler: Scheduler): Flux<T> {\n return this;\n};\n\nFlux.prototype.checkpoint = function checkpoint<T>(\n this: Flux<T>,\n _description?: string,\n _forceStackTrace?: boolean\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextCapture = function contextCapture<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextWrite = function contextWrite<T>(\n this: Flux<T>,\n contextUpdate: ContextView | Context | ((context: Context) => Context)\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return source.iterate(signal, nextContext);\n },\n subscriber => {\n const context = subscriberContext(subscriber);\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return {\n onNext: passThrough,\n currentContext: () => nextContext\n };\n }\n );\n};\n\nFlux.prototype.delaySequence = function delaySequence<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler?: Scheduler\n): Flux<T> {\n return this.delaySubscription(delay, scheduler);\n};\n\nFlux.prototype.delaySubscription = function delaySubscription<T>(\n this: Flux<T>,\n delay: DurationInput | PublisherInput<unknown>,\n scheduler?: Scheduler\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n if (isDuration(delay)) {\n await scheduleDelay(scheduler ?? Schedulers.timeout(), delay, signal);\n } else {\n await drain(delay, signal, context);\n }\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.delayUntil = function delayUntil<T>(\n this: Flux<T>,\n triggerProvider: (value: T) => PublisherInput<unknown>\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await drain(triggerProvider(value), signal, context);\n yield value;\n }\n });\n};\n\nFlux.prototype.doAfterTerminate = function doAfterTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let terminated = false;\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n terminated = true;\n } finally {\n if (terminated) {\n callback();\n }\n }\n });\n};\n\nFlux.prototype.doFirst = function doFirst<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n callback();\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnCancel = function doOnCancel<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n signal.addEventListener(\"abort\", callback, {once: true});\n return source.iterate(signal, context);\n });\n};\n\nFlux.prototype.doOnDiscard = function doOnDiscard<T, R>(\n this: Flux<T>,\n _type: new (...args: never[]) => R,\n _callback: (value: R) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.doOnEach = function doOnEach<T>(this: Flux<T>, callback: (signal: Signal<T>) => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n callback(Signal.next(value));\n yield value;\n }\n callback(Signal.complete());\n } catch (error) {\n callback(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.doOnRequest = function doOnRequest<T>(this: Flux<T>, callback: (request: number) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(Number.POSITIVE_INFINITY);\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onRequest: callback\n })\n );\n};\n\nFlux.prototype.doOnSubscribe = function doOnSubscribe<T>(\n this: Flux<T>,\n callback: (subscription: Subscription) => void\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(noopSubscription());\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onSubscribe: callback\n })\n );\n};\n\nFlux.prototype.doOnTerminate = function doOnTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n callback();\n } catch (error) {\n callback();\n throw error;\n }\n });\n};\n\nFlux.prototype.limitRate = function limitRate<T>(this: Flux<T>, _highTide: number, _lowTide?: number): Flux<T> {\n return this;\n};\n\nFlux.prototype.limitRequest = function limitRequest<T>(this: Flux<T>, n: number): Flux<T> {\n return this.take(n);\n};\n\nFlux.prototype.log = function log<T>(this: Flux<T>, category = \"Flux\"): Flux<T> {\n return this.doOnEach(signal => console.debug(category, signal.type, signal.value ?? signal.error));\n};\n\nFlux.prototype.metrics = function metrics<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.name = function name<T>(this: Flux<T>, _name: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureBuffer = function onBackpressureBuffer<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureDrop = function onBackpressureDrop<T>(\n this: Flux<T>,\n _callback?: (value: T) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureError = function onBackpressureError<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureLatest = function onBackpressureLatest<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onErrorComplete = function onErrorComplete<T>(\n this: Flux<T>,\n predicate: (error: unknown) => boolean = () => true\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n } catch (error) {\n if (!predicate(error)) {\n throw error;\n }\n }\n });\n};\n\nFlux.prototype.onErrorContinue = function onErrorContinue<T>(\n this: Flux<T>,\n callback: (error: unknown, value: T | undefined) => void\n): Flux<T> {\n return this.onErrorResume(error => {\n callback(error, undefined);\n return Flux.empty<T>();\n });\n};\n\nFlux.prototype.onErrorStop = function onErrorStop<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onTerminateDetach = function onTerminateDetach<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.publish = function publish<T, R = T>(\n this: Flux<T>,\n transformer?: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n return transformer ? Flux.from(transformer(this.share())) : (this.share() as unknown as Flux<R>);\n};\n\nFlux.prototype.publishNext = function publishNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.replay = function replay<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this.cache();\n};\n\nFlux.prototype.share = function share<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.shareNext = function shareNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.tag = function tag<T>(this: Flux<T>, _key: string, _value: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.tap = function tap<T>(this: Flux<T>, listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const actual = typeof listener === \"function\" ? listener() : listener;\n signal.addEventListener(\"abort\", () => actual.onCancel?.(), {once: true});\n try {\n for await (const value of source.iterate(signal, context)) {\n actual.onNext?.(value);\n actual.onSignal?.(Signal.next(value));\n yield value;\n }\n actual.onComplete?.();\n actual.onSignal?.(Signal.complete());\n } catch (error) {\n actual.onError?.(error);\n actual.onSignal?.(Signal.error(error));\n throw error;\n }\n });\n};\n\nFlux.prototype.toStream = function toStream<T>(this: Flux<T>): AsyncIterable<T> {\n return this;\n};\n\n/** Returns true when a value can be treated as a duration input. */\nfunction isDuration(value: unknown): value is DurationInput {\n return typeof value === \"number\" || (typeof value === \"object\" && value !== null && !isPublisherLike(value));\n}\n\n/** Returns true when a value looks like a publisher or iterable source. */\nfunction isPublisherLike(value: object): boolean {\n return (\n typeof (value as { subscribe?: unknown }).subscribe === \"function\" ||\n typeof (value as { then?: unknown }).then === \"function\" ||\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\" ||\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === \"function\"\n );\n}\n\n/** Consumes a publisher input and ignores all emitted values. */\nasync function drain(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<void> {\n for await (const _ of Flux.from(source).iterate(signal, context)) {\n // ignored\n }\n}\n\n/** Creates a no-op subscription object for doOnSubscribe callbacks. */\nfunction noopSubscription(): Subscription {\n return {\n /** Ignores request accounting for synthetic subscriptions. */\n request() {\n // no-op\n },\n /** Ignores cancellation for synthetic subscriptions. */\n cancel() {\n // no-op\n }\n };\n}\n\n/** Returns an operator value unchanged. */\nfunction passThrough<T>(value: T): T {\n return value;\n}\n"],"mappings":";;;;;;AAqJA,KAAK,UAAU,QAAQ,SAAS,MAAwB,MAAsB,YAAiC;CAC3G,MAAM,SAAS;CACf,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAA,UAAY,YAAY;GACpB,MAAM,aAAkB,CAAC;GACzB,IAAI;IACA,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GACpD,WAAW,KAAK,KAAK;IAEzB,SAAS;GACb,SAAS,OAAO;IACZ,UAAU;GACd;EACJ,EAAA,CAAG;EACH,MAAM;EACN,IAAI,YAAY,QACZ,MAAM;EAEV,OAAO,UAAU,CAAC;CACtB,CAAC;AACL;AAEA,KAAK,UAAU,WAAW,SAAS,SAA2B,YAAgC;CAC1F,OAAO;AACX;AAEA,KAAK,UAAU,aAAa,SAAS,WAEjC,cACA,kBACO;CACP,OAA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AO,SAAS,CAAC;EACvC,SAAS,OAAO;GACZ,OAAO,UAAU,KAAK;GACtB,OAAO,WAAW,OAAO,MAAM,KAAK,CAAC;GACrC,MAAM;EACV;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,WAAW,SAAS,WAA6C;CAC5E,OAAO;AACX;;AAGA,SAAS,WAAW,OAAwC;CACxD,OAAO,OAAO,UAAU,YAAa,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,gBAAgB,KAAK;AAC9G;;AAGA,SAAS,gBAAgB,OAAwB;CAC7C,OACI,OAAQ,MAAkC,cAAc,cACxD,OAAQ,MAA6B,SAAS,cAC9C,OAAQ,MAA0C,OAAO,cAAc,cACvE,OAAQ,MAA+C,OAAO,mBAAmB;AAEzF;;AAGA,eAAe,MAAM,QAAiC,QAAqB,SAAiC;CACxG,WAAW,MAAM,KAAK,KAAK,KAAK,MAAM,CAAC,CAAC,QAAQ,QAAQ,OAAO;AAGnE;;AAGA,SAAS,mBAAiC;CACtC,OAAO;;EAEH,UAAU,CAEV;;EAEA,SAAS,CAET;CACJ;AACJ;;AAGA,SAAS,YAAe,OAAa;CACjC,OAAO;AACX"}
|
|
1
|
+
{"version":3,"file":"lifecycle.js","names":[],"sources":["../../../src/publisher/operators/lifecycle.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactor lifecycle, context, logging and browser backpressure compatibility operators.\n */\nimport {Context} from \"@/context/context.js\";\nimport {ContextView} from \"@/context/context-view.js\";\nimport {UNBOUNDED_DEMAND} from \"@/core/demand.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {collectPublisher, drainPublisher} from \"@/internal/publisher-terminal.js\";\nimport {scheduleDelay} from \"@/publisher/helpers.js\";\nimport {liftOneToOne, subscriberContext} from \"@/publisher/operators/lift.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\nimport {Signal} from \"@/signal/signal.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Listener shape accepted by the lightweight `tap` compatibility operator. */\nexport interface FluxTapListener<T> {\n /** Invoked for each next value. */\n onNext?(value: T): void;\n\n /** Invoked when the sequence fails. */\n onError?(error: unknown): void;\n\n /** Invoked when the sequence completes. */\n onComplete?(): void;\n\n /** Invoked when the sequence is cancelled. */\n onCancel?(): void;\n\n /** Invoked for materialized next, error and complete signals. */\n onSignal?(signal: Signal<T>): void;\n}\n\ndeclare module \"@/publisher/flux.js\" {\n /** Lifecycle, context and browser backpressure compatibility operators added to Flux. */\n interface Flux<T> {\n /** Replays the collected source values to later subscribers. */\n cache(ttl?: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Schedules cancellation on the provided scheduler when supported by the source. */\n cancelOn(scheduler: Scheduler): Flux<T>;\n\n /** Adds an assembly checkpoint marker. Browser implementation keeps the source unchanged. */\n checkpoint(description?: string, forceStackTrace?: boolean): Flux<T>;\n\n /** Captures ambient context when an integration provides it. Browser implementation keeps the source unchanged. */\n contextCapture(): Flux<T>;\n\n /** Writes subscriber context for upstream operators. */\n contextWrite(context: ContextView | Context | ((context: Context) => Context)): Flux<T>;\n\n /** Delays subscribing to the source. */\n delaySequence(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Delays subscribing to the source by time or until another publisher signals. */\n delaySubscription(delay: DurationInput | PublisherInput<unknown>, scheduler?: Scheduler): Flux<T>;\n\n /** Delays each value until the trigger publisher derived from that value completes. */\n delayUntil(triggerProvider: (value: T) => PublisherInput<unknown>): Flux<T>;\n\n /** Invokes a callback after successful or failed termination. */\n doAfterTerminate(callback: () => void): Flux<T>;\n\n /** Invokes a callback before source iteration starts. */\n doFirst(callback: () => void): Flux<T>;\n\n /** Invokes a callback when the subscription is cancelled. */\n doOnCancel(callback: () => void): Flux<T>;\n\n /** Registers a discard hook. Browser implementation keeps values unchanged. */\n doOnDiscard<R>(type: new (...args: never[]) => R, callback: (value: R) => void): Flux<T>;\n\n /** Invokes a callback for every materialized source signal. */\n doOnEach(callback: (signal: Signal<T>) => void): Flux<T>;\n\n /** Invokes a callback when unbounded demand is requested by the async bridge. */\n doOnRequest(callback: (request: number) => void): Flux<T>;\n\n /** Invokes a callback with a synthetic subscription before source iteration starts. */\n doOnSubscribe(callback: (subscription: Subscription) => void): Flux<T>;\n\n /** Invokes a callback before successful or failed termination. */\n doOnTerminate(callback: () => void): Flux<T>;\n\n /** Keeps request batching metadata. Browser async iteration returns this source unchanged. */\n limitRate(highTide: number, lowTide?: number): Flux<T>;\n\n /** Limits the total number of requested values. */\n limitRequest(n: number): Flux<T>;\n\n /** Logs source signals to the console. */\n log(category?: string): Flux<T>;\n\n /** Keeps metrics compatibility metadata. Browser implementation returns this source unchanged. */\n metrics(): Flux<T>;\n\n /** Keeps a human-readable sequence name. Browser implementation returns this source unchanged. */\n name(name: string): Flux<T>;\n\n /** Buffers on backpressure. Browser async iteration already buffers by pull demand. */\n onBackpressureBuffer(...args: unknown[]): Flux<T>;\n\n /** Drops on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureDrop(callback?: (value: T) => void): Flux<T>;\n\n /** Fails on backpressure. Browser async iteration keeps pull demand and returns this source unchanged. */\n onBackpressureError(): Flux<T>;\n\n /** Keeps only the latest value on backpressure. Browser async iteration returns this source unchanged. */\n onBackpressureLatest(): Flux<T>;\n\n /** Completes instead of failing when the optional predicate accepts the error. */\n onErrorComplete(predicate?: (error: unknown) => boolean): Flux<T>;\n\n /** Continues with completion after invoking an error continuation callback. */\n onErrorContinue(callback: (error: unknown, value: T | undefined) => void): Flux<T>;\n\n /** Stops error continuation mode. Browser implementation returns this source unchanged. */\n onErrorStop(): Flux<T>;\n\n /** Drops terminal-reference retention hints. Browser implementation returns this source unchanged. */\n onTerminateDetach(): Flux<T>;\n\n /** Transforms a shared source or returns a shared source view. */\n publish<R = T>(transformer?: (source: Flux<T>) => PublisherInput<R>): Flux<R>;\n\n /** Returns a Mono with the next value from this source. */\n publishNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Returns a replaying view of this source. */\n replay(...args: unknown[]): Flux<T>;\n\n /** Returns a shared browser view of this source. */\n share(): Flux<T>;\n\n /** Returns a Mono with the next value from a shared source. */\n shareNext(): import(\"@/publisher/mono.js\").Mono<T>;\n\n /** Stores a metadata tag. Browser implementation returns this source unchanged. */\n tag(key: string, value: string): Flux<T>;\n\n /** Installs listener callbacks for values, terminal signals, and cancellation. */\n tap(listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T>;\n\n /** Returns an async iterator stream view of this Flux. */\n toStream(): AsyncIterable<T>;\n }\n}\n\nFlux.prototype.cache = function cache<T>(this: Flux<T>, _ttl?: DurationInput, _scheduler?: Scheduler): Flux<T> {\n const source = this;\n let values: T[] | undefined;\n let failure: unknown;\n let loaded: Promise<void> | undefined;\n return new Flux(async function* (signal, context) {\n loaded ??= collectPublisher<T>(source, signal, context).then(\n nextValues => {\n values = nextValues;\n },\n error => {\n failure = error;\n }\n );\n await loaded;\n if (failure !== undefined) {\n throw failure;\n }\n yield* values ?? [];\n });\n};\n\nFlux.prototype.cancelOn = function cancelOn<T>(this: Flux<T>, _scheduler: Scheduler): Flux<T> {\n return this;\n};\n\nFlux.prototype.checkpoint = function checkpoint<T>(\n this: Flux<T>,\n _description?: string,\n _forceStackTrace?: boolean\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextCapture = function contextCapture<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.contextWrite = function contextWrite<T>(\n this: Flux<T>,\n contextUpdate: ContextView | Context | ((context: Context) => Context)\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return source.iterate(signal, nextContext);\n },\n subscriber => {\n const context = subscriberContext(subscriber);\n const nextContext =\n typeof contextUpdate === \"function\"\n ? contextUpdate(context)\n : context.putAll(contextUpdate);\n return {\n onNext: passThrough,\n currentContext: () => nextContext\n };\n }\n );\n};\n\nFlux.prototype.delaySequence = function delaySequence<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler?: Scheduler\n): Flux<T> {\n return this.delaySubscription(delay, scheduler);\n};\n\nFlux.prototype.delaySubscription = function delaySubscription<T>(\n this: Flux<T>,\n delay: DurationInput | PublisherInput<unknown>,\n scheduler?: Scheduler\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n if (isDuration(delay)) {\n await scheduleDelay(scheduler ?? Schedulers.timeout(), delay, signal);\n } else {\n await drain(delay, signal, context);\n }\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n });\n};\n\nFlux.prototype.delayUntil = function delayUntil<T>(\n this: Flux<T>,\n triggerProvider: (value: T) => PublisherInput<unknown>\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await drain(triggerProvider(value), signal, context);\n yield value;\n }\n });\n};\n\nFlux.prototype.doAfterTerminate = function doAfterTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n let terminated = false;\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n terminated = true;\n } finally {\n if (terminated) {\n callback();\n }\n }\n },\n () => ({\n onNext: passThrough,\n /** Runs the callback after non-cancellation terminal signals. */\n onFinally(signal) {\n if (signal !== \"cancel\") {\n callback();\n }\n }\n })\n );\n};\n\nFlux.prototype.doFirst = function doFirst<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback();\n return source.iterate(signal, context);\n },\n () => {\n callback();\n return {onNext: passThrough};\n }\n );\n};\n\nFlux.prototype.doOnCancel = function doOnCancel<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n signal.addEventListener(\"abort\", callback, {once: true});\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onCancel: callback\n })\n );\n};\n\nFlux.prototype.doOnDiscard = function doOnDiscard<T, R>(\n this: Flux<T>,\n _type: new (...args: never[]) => R,\n _callback: (value: R) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.doOnEach = function doOnEach<T>(this: Flux<T>, callback: (signal: Signal<T>) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n callback(Signal.next(value));\n yield value;\n }\n callback(Signal.complete());\n } catch (error) {\n callback(Signal.error(error));\n throw error;\n }\n },\n () => ({\n /** Observes one next signal and relays its value. */\n onNext(value) {\n callback(Signal.next(value));\n return value;\n },\n onError: error => callback(Signal.error(error)),\n onComplete: () => callback(Signal.complete())\n })\n );\n};\n\nFlux.prototype.doOnRequest = function doOnRequest<T>(this: Flux<T>, callback: (request: number) => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(UNBOUNDED_DEMAND);\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onRequest: callback\n })\n );\n};\n\nFlux.prototype.doOnSubscribe = function doOnSubscribe<T>(\n this: Flux<T>,\n callback: (subscription: Subscription) => void\n): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n (signal, context) => {\n callback(noopSubscription());\n return source.iterate(signal, context);\n },\n () => ({\n onNext: passThrough,\n onSubscribe: callback\n })\n );\n};\n\nFlux.prototype.doOnTerminate = function doOnTerminate<T>(this: Flux<T>, callback: () => void): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n callback();\n } catch (error) {\n callback();\n throw error;\n }\n },\n () => ({\n onNext: passThrough,\n onError: callback,\n onComplete: callback\n })\n );\n};\n\nFlux.prototype.limitRate = function limitRate<T>(this: Flux<T>, _highTide: number, _lowTide?: number): Flux<T> {\n return this;\n};\n\nFlux.prototype.limitRequest = function limitRequest<T>(this: Flux<T>, n: number): Flux<T> {\n return this.take(n);\n};\n\nFlux.prototype.log = function log<T>(this: Flux<T>, category = \"Flux\"): Flux<T> {\n return this.doOnEach(signal => console.debug(category, signal.type, signal.value ?? signal.error));\n};\n\nFlux.prototype.metrics = function metrics<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.name = function name<T>(this: Flux<T>, _name: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureBuffer = function onBackpressureBuffer<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureDrop = function onBackpressureDrop<T>(\n this: Flux<T>,\n _callback?: (value: T) => void\n): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureError = function onBackpressureError<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onBackpressureLatest = function onBackpressureLatest<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onErrorComplete = function onErrorComplete<T>(\n this: Flux<T>,\n predicate: (error: unknown) => boolean = () => true\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n try {\n for await (const value of source.iterate(signal, context)) {\n yield value;\n }\n } catch (error) {\n if (!predicate(error)) {\n throw error;\n }\n }\n });\n};\n\nFlux.prototype.onErrorContinue = function onErrorContinue<T>(\n this: Flux<T>,\n callback: (error: unknown, value: T | undefined) => void\n): Flux<T> {\n return this.onErrorResume(error => {\n callback(error, undefined);\n return Flux.empty<T>();\n });\n};\n\nFlux.prototype.onErrorStop = function onErrorStop<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.onTerminateDetach = function onTerminateDetach<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.publish = function publish<T, R = T>(\n this: Flux<T>,\n transformer?: (source: Flux<T>) => PublisherInput<R>\n): Flux<R> {\n return transformer ? Flux.from(transformer(this.share())) : (this.share() as unknown as Flux<R>);\n};\n\nFlux.prototype.publishNext = function publishNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.replay = function replay<T>(this: Flux<T>, ..._args: unknown[]): Flux<T> {\n return this.cache();\n};\n\nFlux.prototype.share = function share<T>(this: Flux<T>): Flux<T> {\n return this;\n};\n\nFlux.prototype.shareNext = function shareNext<T>(this: Flux<T>) {\n return this.next();\n};\n\nFlux.prototype.tag = function tag<T>(this: Flux<T>, _key: string, _value: string): Flux<T> {\n return this;\n};\n\nFlux.prototype.tap = function tap<T>(this: Flux<T>, listener: FluxTapListener<T> | (() => FluxTapListener<T>)): Flux<T> {\n const source = this;\n return liftOneToOne(\n source,\n async function* (signal, context) {\n const actual = typeof listener === \"function\" ? listener() : listener;\n signal.addEventListener(\"abort\", () => actual.onCancel?.(), {once: true});\n try {\n for await (const value of source.iterate(signal, context)) {\n actual.onNext?.(value);\n actual.onSignal?.(Signal.next(value));\n yield value;\n }\n actual.onComplete?.();\n actual.onSignal?.(Signal.complete());\n } catch (error) {\n actual.onError?.(error);\n actual.onSignal?.(Signal.error(error));\n throw error;\n }\n },\n () => {\n const actual = typeof listener === \"function\" ? listener() : listener;\n return {\n /** Notifies the listener about one value and relays it. */\n onNext(value) {\n actual.onNext?.(value);\n actual.onSignal?.(Signal.next(value));\n return value;\n },\n /** Notifies the listener about an error signal. */\n onError(error) {\n actual.onError?.(error);\n actual.onSignal?.(Signal.error(error));\n },\n /** Notifies the listener about successful completion. */\n onComplete() {\n actual.onComplete?.();\n actual.onSignal?.(Signal.complete());\n },\n onCancel: () => actual.onCancel?.()\n };\n }\n );\n};\n\nFlux.prototype.toStream = function toStream<T>(this: Flux<T>): AsyncIterable<T> {\n return this;\n};\n\n/** Returns true when a value can be treated as a duration input. */\nfunction isDuration(value: unknown): value is DurationInput {\n return typeof value === \"number\" || (typeof value === \"object\" && value !== null && !isPublisherLike(value));\n}\n\n/** Returns true when a value looks like a publisher or iterable source. */\nfunction isPublisherLike(value: object): boolean {\n return (\n typeof (value as { subscribe?: unknown }).subscribe === \"function\" ||\n typeof (value as { then?: unknown }).then === \"function\" ||\n typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === \"function\" ||\n typeof (value as { [Symbol.asyncIterator]?: unknown })[Symbol.asyncIterator] === \"function\"\n );\n}\n\n/** Consumes a publisher input and ignores all emitted values. */\nasync function drain(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<void> {\n await drainPublisher(Flux.from(source), signal, context);\n}\n\n/** Creates a no-op subscription object for doOnSubscribe callbacks. */\nfunction noopSubscription(): Subscription {\n return {\n /** Ignores request accounting for synthetic subscriptions. */\n request() {\n // no-op\n },\n /** Ignores cancellation for synthetic subscriptions. */\n cancel() {\n // no-op\n }\n };\n}\n\n/** Returns an operator value unchanged. */\nfunction passThrough<T>(value: T): T {\n return value;\n}\n"],"mappings":";;;;;;;;AAuJA,KAAK,UAAU,QAAQ,SAAS,MAAwB,MAAsB,YAAiC;CAC3G,MAAM,SAAS;CACf,IAAI;CACJ,IAAI;CACJ,IAAI;CACJ,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAA,SAAW,iBAAoB,QAAQ,QAAQ,OAAO,CAAC,CAAC,MACpD,eAAc;GACV,SAAS;EACb,IACA,UAAS;GACL,UAAU;EACd,CACJ;EACA,MAAM;EACN,IAAI,YAAY,QACZ,MAAM;EAEV,OAAO,UAAU,CAAC;CACtB,CAAC;AACL;AAEA,KAAK,UAAU,WAAW,SAAS,SAA2B,YAAgC;CAC1F,OAAO;AACX;AAEA,KAAK,UAAU,aAAa,SAAS,WAEjC,cACA,kBACO;CACP,OAAO;AACX;AAEA,KAAK,UAAU,iBAAiB,SAAS,iBAA0C;CAC/E,OAAO;AACX;AAEA,KAAK,UAAU,eAAe,SAAS,aAEnC,eACO;CACP,MAAM,SAAS;CACf,OAAO,aACH,SACC,QAAQ,YAAY;EACjB,MAAM,cACF,OAAO,kBAAkB,aACnB,cAA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|
@@ -37,6 +37,8 @@ export declare function liftFlux<T, R>(source: Flux<T>, sourceFactory: SourceFac
|
|
|
37
37
|
export declare function liftOneToOne<T, R>(source: Flux<T>, sourceFactory: SourceFactory<R>, hooksFactory: (subscriber: Subscriber<R>) => OneToOneOperatorHooks<T, R>): Flux<R>;
|
|
38
38
|
/** Creates a filtering operator that replenishes only values dropped from finite demand. */
|
|
39
39
|
export declare function liftFilter<T>(source: Flux<T>, sourceFactory: SourceFactory<T>, predicate: (value: T) => boolean): Flux<T>;
|
|
40
|
+
/** Creates a limiting operator that never requests more than its remaining item count. */
|
|
41
|
+
export declare function liftTake<T>(source: Flux<T>, sourceFactory: SourceFactory<T>, count: number): Flux<T>;
|
|
40
42
|
/** Returns the context exposed by a subscriber, or the shared empty context. */
|
|
41
43
|
export declare function subscriberContext<T>(subscriber: Subscriber<T>): Context;
|
|
42
44
|
//# sourceMappingURL=lift.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lift.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/lift.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"lift.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/lift.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAG7C,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAEzC,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAEjE,qFAAqF;AACrF,MAAM,MAAM,gBAAgB,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,K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B,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EACf,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,EAC/B,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,OAAO,GACjC,IAAI,CAAC,CAAC,CAAC,CAET;AAED,0FAA0F;AAC1F,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAEpG;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,OAAO,CAEvE"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "../../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
2
|
import { Context } from "../../context/context.js";
|
|
3
|
-
import { addCap } from "../../core/demand.js";
|
|
3
|
+
import { UNBOUNDED_DEMAND, addCap, normalizeRequest } from "../../core/demand.js";
|
|
4
|
+
import { ITERATION_DEMAND_HINT, iterationDemandHint } from "../../internal/iteration-demand.js";
|
|
4
5
|
import { Flux } from "../flux.js";
|
|
5
6
|
//#region src/publisher/operators/lift.ts
|
|
6
7
|
/**
|
|
@@ -22,6 +23,10 @@ function liftOneToOne(source, sourceFactory, hooksFactory) {
|
|
|
22
23
|
function liftFilter(source, sourceFactory, predicate) {
|
|
23
24
|
return liftFlux(source, sourceFactory, (subscriber) => new FilterOperatorSubscriber(subscriber, predicate));
|
|
24
25
|
}
|
|
26
|
+
/** Creates a limiting operator that never requests more than its remaining item count. */
|
|
27
|
+
function liftTake(source, sourceFactory, count) {
|
|
28
|
+
return liftFlux(source, sourceFactory, (subscriber) => new TakeOperatorSubscriber(subscriber, count));
|
|
29
|
+
}
|
|
25
30
|
/** Returns the context exposed by a subscriber, or the shared empty context. */
|
|
26
31
|
function subscriberContext(subscriber) {
|
|
27
32
|
return subscriber.currentContext?.() ?? Context.empty();
|
|
@@ -114,6 +119,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
114
119
|
this.terminateWithError(error, true);
|
|
115
120
|
return;
|
|
116
121
|
}
|
|
122
|
+
if (this.terminated) return;
|
|
117
123
|
this.actual.onNext(mapped);
|
|
118
124
|
}
|
|
119
125
|
/** Forwards an upstream error after running the operator callback. */
|
|
@@ -129,6 +135,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
129
135
|
this.terminateWithError(error, false);
|
|
130
136
|
return;
|
|
131
137
|
}
|
|
138
|
+
if (this.terminated) return;
|
|
132
139
|
this.terminated = true;
|
|
133
140
|
try {
|
|
134
141
|
this.actual.onComplete();
|
|
@@ -145,6 +152,7 @@ var OneToOneOperatorSubscriber = class {
|
|
|
145
152
|
this.terminateWithError(error, true);
|
|
146
153
|
return;
|
|
147
154
|
}
|
|
155
|
+
if (this.terminated) return;
|
|
148
156
|
this.upstream?.request(n);
|
|
149
157
|
}
|
|
150
158
|
/** Cancels upstream once and reports the cancellation lifecycle hooks. */
|
|
@@ -165,6 +173,10 @@ var OneToOneOperatorSubscriber = class {
|
|
|
165
173
|
currentContext() {
|
|
166
174
|
return this.hooks.currentContext?.() ?? subscriberContext(this.actual);
|
|
167
175
|
}
|
|
176
|
+
/** Propagates a known terminal demand batch through this one-to-one boundary. */
|
|
177
|
+
[ITERATION_DEMAND_HINT]() {
|
|
178
|
+
return iterationDemandHint(this.actual);
|
|
179
|
+
}
|
|
168
180
|
/** Cancels when needed and emits one downstream error signal. */
|
|
169
181
|
terminateWithError(error, cancelUpstream) {
|
|
170
182
|
if (this.terminated) return;
|
|
@@ -284,7 +296,7 @@ var FilterOperatorSubscriber = class {
|
|
|
284
296
|
/** Forwards demand and records when no further compensation is necessary. */
|
|
285
297
|
request(n) {
|
|
286
298
|
if (this.terminated) return;
|
|
287
|
-
if (n ===
|
|
299
|
+
if (n === UNBOUNDED_DEMAND) this.unbounded = true;
|
|
288
300
|
this.requestUpstream(n);
|
|
289
301
|
}
|
|
290
302
|
/** Cancels the upstream once. */
|
|
@@ -297,6 +309,10 @@ var FilterOperatorSubscriber = class {
|
|
|
297
309
|
currentContext() {
|
|
298
310
|
return subscriberContext(this.actual);
|
|
299
311
|
}
|
|
312
|
+
/** Propagates a known unbounded terminal batch through this filtering boundary. */
|
|
313
|
+
[ITERATION_DEMAND_HINT]() {
|
|
314
|
+
return iterationDemandHint(this.actual);
|
|
315
|
+
}
|
|
300
316
|
/** Drains demand iteratively so synchronous sources cannot recurse through dropped values. */
|
|
301
317
|
requestUpstream(n) {
|
|
302
318
|
if (this.requesting) {
|
|
@@ -319,6 +335,160 @@ var FilterOperatorSubscriber = class {
|
|
|
319
335
|
}
|
|
320
336
|
}
|
|
321
337
|
};
|
|
338
|
+
/** Subscriber that caps cumulative upstream demand and completes after a fixed number of values. */
|
|
339
|
+
var TakeOperatorSubscriber = class {
|
|
340
|
+
/** Creates a take subscriber with the provided maximum value count. */
|
|
341
|
+
constructor(actual, count) {
|
|
342
|
+
_defineProperty(this, "actual", void 0);
|
|
343
|
+
_defineProperty(
|
|
344
|
+
this,
|
|
345
|
+
/** Active upstream subscription. */
|
|
346
|
+
"upstream",
|
|
347
|
+
void 0
|
|
348
|
+
);
|
|
349
|
+
_defineProperty(
|
|
350
|
+
this,
|
|
351
|
+
/** Remaining values before this operator completes. */
|
|
352
|
+
"remaining",
|
|
353
|
+
void 0
|
|
354
|
+
);
|
|
355
|
+
_defineProperty(
|
|
356
|
+
this,
|
|
357
|
+
/** Requested upstream values that have not arrived yet. */
|
|
358
|
+
"outstanding",
|
|
359
|
+
0
|
|
360
|
+
);
|
|
361
|
+
_defineProperty(
|
|
362
|
+
this,
|
|
363
|
+
/** Guards synchronous upstream request calls against recursive downstream demand. */
|
|
364
|
+
"requesting",
|
|
365
|
+
false
|
|
366
|
+
);
|
|
367
|
+
_defineProperty(
|
|
368
|
+
this,
|
|
369
|
+
/** Downstream demand accumulated while an upstream request is active. */
|
|
370
|
+
"missedRequested",
|
|
371
|
+
0
|
|
372
|
+
);
|
|
373
|
+
_defineProperty(
|
|
374
|
+
this,
|
|
375
|
+
/** Prevents duplicate subscriptions from replacing the active upstream. */
|
|
376
|
+
"subscribed",
|
|
377
|
+
false
|
|
378
|
+
);
|
|
379
|
+
_defineProperty(
|
|
380
|
+
this,
|
|
381
|
+
/** Suppresses signals after cancellation or termination. */
|
|
382
|
+
"terminated",
|
|
383
|
+
false
|
|
384
|
+
);
|
|
385
|
+
this.actual = actual;
|
|
386
|
+
this.remaining = count;
|
|
387
|
+
}
|
|
388
|
+
/** Stores upstream and exposes the capped subscription downstream. */
|
|
389
|
+
onSubscribe(subscription) {
|
|
390
|
+
if (this.subscribed || this.terminated) {
|
|
391
|
+
cancelSilently(subscription);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
this.subscribed = true;
|
|
395
|
+
this.upstream = subscription;
|
|
396
|
+
try {
|
|
397
|
+
this.actual.onSubscribe(this);
|
|
398
|
+
} catch (error) {
|
|
399
|
+
this.terminated = true;
|
|
400
|
+
cancelSilently(subscription);
|
|
401
|
+
throw error;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
/** Forwards one value and cancels upstream exactly at the configured limit. */
|
|
405
|
+
onNext(value) {
|
|
406
|
+
if (this.terminated || this.remaining === 0) return;
|
|
407
|
+
if (this.outstanding > 0) this.outstanding -= 1;
|
|
408
|
+
this.remaining -= 1;
|
|
409
|
+
try {
|
|
410
|
+
this.actual.onNext(value);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
if (this.terminated) return;
|
|
413
|
+
this.terminated = true;
|
|
414
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
415
|
+
this.actual.onError(error);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
if (this.remaining === 0 && !this.terminated) {
|
|
419
|
+
this.terminated = true;
|
|
420
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
421
|
+
this.actual.onComplete();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
/** Forwards the first upstream failure. */
|
|
425
|
+
onError(error) {
|
|
426
|
+
if (this.terminated) return;
|
|
427
|
+
this.terminated = true;
|
|
428
|
+
this.actual.onError(error);
|
|
429
|
+
}
|
|
430
|
+
/** Forwards early upstream completion. */
|
|
431
|
+
onComplete() {
|
|
432
|
+
if (this.terminated) return;
|
|
433
|
+
this.terminated = true;
|
|
434
|
+
this.actual.onComplete();
|
|
435
|
+
}
|
|
436
|
+
/** Requests only demand that still fits below the take limit. */
|
|
437
|
+
request(n) {
|
|
438
|
+
if (this.terminated) return;
|
|
439
|
+
let demand;
|
|
440
|
+
try {
|
|
441
|
+
demand = normalizeRequest(n);
|
|
442
|
+
} catch (error) {
|
|
443
|
+
this.terminated = true;
|
|
444
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
445
|
+
this.actual.onError(error);
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
if (this.requesting) {
|
|
449
|
+
this.missedRequested = addCap(this.missedRequested, demand);
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this.requesting = true;
|
|
453
|
+
let nextDemand = demand;
|
|
454
|
+
try {
|
|
455
|
+
while (!this.terminated) {
|
|
456
|
+
const available = this.remaining - this.outstanding;
|
|
457
|
+
if (available > 0) {
|
|
458
|
+
const request = Math.min(nextDemand, available);
|
|
459
|
+
this.outstanding += request;
|
|
460
|
+
this.upstream?.request(request);
|
|
461
|
+
}
|
|
462
|
+
if (this.terminated || this.missedRequested === 0) return;
|
|
463
|
+
nextDemand = this.missedRequested;
|
|
464
|
+
this.missedRequested = 0;
|
|
465
|
+
}
|
|
466
|
+
} catch (error) {
|
|
467
|
+
if (!this.terminated) {
|
|
468
|
+
this.terminated = true;
|
|
469
|
+
if (this.upstream) cancelSilently(this.upstream);
|
|
470
|
+
this.actual.onError(error);
|
|
471
|
+
}
|
|
472
|
+
} finally {
|
|
473
|
+
this.requesting = false;
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
/** Cancels the active upstream once. */
|
|
477
|
+
cancel() {
|
|
478
|
+
if (this.terminated) return;
|
|
479
|
+
this.terminated = true;
|
|
480
|
+
this.upstream?.cancel();
|
|
481
|
+
}
|
|
482
|
+
/** Exposes the downstream context unchanged. */
|
|
483
|
+
currentContext() {
|
|
484
|
+
return subscriberContext(this.actual);
|
|
485
|
+
}
|
|
486
|
+
/** Propagates downstream demand metadata while `take` still applies its own cap. */
|
|
487
|
+
[ITERATION_DEMAND_HINT]() {
|
|
488
|
+
const downstream = iterationDemandHint(this.actual);
|
|
489
|
+
return downstream === void 0 ? void 0 : Math.min(downstream, this.remaining);
|
|
490
|
+
}
|
|
491
|
+
};
|
|
322
492
|
/** Signals a lifter assembly failure through a valid Reactive Streams handshake. */
|
|
323
493
|
function signalAssemblyError(subscriber, error) {
|
|
324
494
|
subscriber.onSubscribe(EMPTY_SUBSCRIPTION);
|
|
@@ -338,6 +508,6 @@ var EMPTY_SUBSCRIPTION = Object.freeze({
|
|
|
338
508
|
cancel() {}
|
|
339
509
|
});
|
|
340
510
|
//#endregion
|
|
341
|
-
export { liftFilter, liftFlux, liftOneToOne, subscriberContext };
|
|
511
|
+
export { liftFilter, liftFlux, liftOneToOne, liftTake, subscriberContext };
|
|
342
512
|
|
|
343
513
|
//# sourceMappingURL=lift.js.map
|