reactor-core-ts 2.1.6 → 3.2.1
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 +927 -658
- package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js +12 -0
- package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPrimitive.js +14 -0
- package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/toPropertyKey.js +9 -0
- package/dist/_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/typeof.js +11 -0
- package/dist/context/context-view.d.ts +31 -0
- package/dist/context/context-view.d.ts.map +1 -0
- package/dist/context/context-view.js +58 -0
- package/dist/context/context-view.js.map +1 -0
- package/dist/context/context.d.ts +46 -0
- package/dist/context/context.d.ts.map +1 -0
- package/dist/context/context.js +125 -0
- package/dist/context/context.js.map +1 -0
- package/dist/context/types.d.ts +7 -0
- package/dist/context/types.d.ts.map +1 -0
- package/dist/core/boolean-disposable.d.ts +19 -0
- package/dist/core/boolean-disposable.d.ts.map +1 -0
- package/dist/core/boolean-disposable.js +37 -0
- package/dist/core/boolean-disposable.js.map +1 -0
- package/dist/core/composite-disposable.d.ts +21 -0
- package/dist/core/composite-disposable.d.ts.map +1 -0
- package/dist/core/composite-disposable.js +64 -0
- package/dist/core/composite-disposable.js.map +1 -0
- package/dist/core/demand.d.ts +9 -0
- package/dist/core/demand.d.ts.map +1 -0
- package/dist/core/demand.js +21 -0
- package/dist/core/demand.js.map +1 -0
- package/dist/core/disposables.d.ts +12 -0
- package/dist/core/disposables.d.ts.map +1 -0
- package/dist/core/disposables.js +37 -0
- package/dist/core/disposables.js.map +1 -0
- package/dist/core/teardown.d.ts +4 -0
- package/dist/core/teardown.d.ts.map +1 -0
- package/dist/core/types.d.ts +14 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/errors/classes.d.ts +37 -0
- package/dist/errors/classes.d.ts.map +1 -0
- package/dist/errors/classes.js +53 -0
- package/dist/errors/classes.js.map +1 -0
- package/dist/errors/exceptions.d.ts +15 -0
- package/dist/errors/exceptions.d.ts.map +1 -0
- package/dist/errors/helpers.d.ts +9 -0
- package/dist/errors/helpers.d.ts.map +1 -0
- package/dist/errors/helpers.js +18 -0
- package/dist/errors/helpers.js.map +1 -0
- package/dist/index.d.ts +17 -2556
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -2
- package/dist/internal/abort.d.ts +5 -0
- package/dist/internal/abort.d.ts.map +1 -0
- package/dist/internal/abort.js +36 -0
- package/dist/internal/abort.js.map +1 -0
- package/dist/internal/async-queue.d.ts +48 -0
- package/dist/internal/async-queue.d.ts.map +1 -0
- package/dist/internal/async-queue.js +187 -0
- package/dist/internal/async-queue.js.map +1 -0
- package/dist/internal/iterable-terminal.d.ts +12 -0
- package/dist/internal/iterable-terminal.d.ts.map +1 -0
- package/dist/internal/iterable-terminal.js +49 -0
- package/dist/internal/iterable-terminal.js.map +1 -0
- package/dist/internal/iterable-transform.d.ts +24 -0
- package/dist/internal/iterable-transform.d.ts.map +1 -0
- package/dist/internal/iterable-transform.js +159 -0
- package/dist/internal/iterable-transform.js.map +1 -0
- package/dist/internal/iterable.d.ts +23 -0
- package/dist/internal/iterable.d.ts.map +1 -0
- package/dist/internal/iterable.js +81 -0
- package/dist/internal/iterable.js.map +1 -0
- package/dist/internal/microtask.d.ts +7 -0
- package/dist/internal/microtask.d.ts.map +1 -0
- package/dist/internal/microtask.js +19 -0
- package/dist/internal/microtask.js.map +1 -0
- package/dist/publisher/browser-sources.d.ts +15 -0
- package/dist/publisher/browser-sources.d.ts.map +1 -0
- package/dist/publisher/browser-sources.js +92 -0
- package/dist/publisher/browser-sources.js.map +1 -0
- package/dist/publisher/flux-entrypoint.d.ts +7 -0
- package/dist/publisher/flux-entrypoint.d.ts.map +1 -0
- package/dist/publisher/flux-entrypoint.js +11 -0
- package/dist/publisher/flux-entrypoint.js.map +1 -0
- package/dist/publisher/flux.d.ts +121 -0
- package/dist/publisher/flux.d.ts.map +1 -0
- package/dist/publisher/flux.js +697 -0
- package/dist/publisher/flux.js.map +1 -0
- package/dist/publisher/helpers.d.ts +19 -0
- package/dist/publisher/helpers.d.ts.map +1 -0
- package/dist/publisher/helpers.js +84 -0
- package/dist/publisher/helpers.js.map +1 -0
- package/dist/publisher/mono-entrypoint.d.ts +7 -0
- package/dist/publisher/mono-entrypoint.d.ts.map +1 -0
- package/dist/publisher/mono-entrypoint.js +11 -0
- package/dist/publisher/mono-entrypoint.js.map +1 -0
- package/dist/publisher/mono.d.ts +72 -0
- package/dist/publisher/mono.d.ts.map +1 -0
- package/dist/publisher/mono.js +373 -0
- package/dist/publisher/mono.js.map +1 -0
- package/dist/publisher/operators/aggregate.d.ts +35 -0
- package/dist/publisher/operators/aggregate.d.ts.map +1 -0
- package/dist/publisher/operators/aggregate.js +217 -0
- package/dist/publisher/operators/aggregate.js.map +1 -0
- package/dist/publisher/operators/compat/flux.d.ts +56 -0
- package/dist/publisher/operators/compat/flux.d.ts.map +1 -0
- package/dist/publisher/operators/compat/flux.js +156 -0
- package/dist/publisher/operators/compat/flux.js.map +1 -0
- package/dist/publisher/operators/compat/mono.d.ts +82 -0
- package/dist/publisher/operators/compat/mono.d.ts.map +1 -0
- package/dist/publisher/operators/compat/mono.js +125 -0
- package/dist/publisher/operators/compat/mono.js.map +1 -0
- package/dist/publisher/operators/coordination.d.ts +82 -0
- package/dist/publisher/operators/coordination.d.ts.map +1 -0
- package/dist/publisher/operators/coordination.js +345 -0
- package/dist/publisher/operators/coordination.js.map +1 -0
- package/dist/publisher/operators/error.d.ts +17 -0
- package/dist/publisher/operators/error.d.ts.map +1 -0
- package/dist/publisher/operators/error.js +48 -0
- package/dist/publisher/operators/error.js.map +1 -0
- package/dist/publisher/operators/flatten.d.ts +19 -0
- package/dist/publisher/operators/flatten.d.ts.map +1 -0
- package/dist/publisher/operators/flatten.js +127 -0
- package/dist/publisher/operators/flatten.js.map +1 -0
- package/dist/publisher/operators/lifecycle.d.ts +103 -0
- package/dist/publisher/operators/lifecycle.d.ts.map +1 -0
- package/dist/publisher/operators/lifecycle.js +237 -0
- package/dist/publisher/operators/lifecycle.js.map +1 -0
- package/dist/publisher/operators/mono-parity.d.ts +109 -0
- package/dist/publisher/operators/mono-parity.d.ts.map +1 -0
- package/dist/publisher/operators/mono-parity.js +144 -0
- package/dist/publisher/operators/mono-parity.js.map +1 -0
- package/dist/publisher/operators/mono.d.ts +30 -0
- package/dist/publisher/operators/mono.d.ts.map +1 -0
- package/dist/publisher/operators/mono.js +37 -0
- package/dist/publisher/operators/mono.js.map +1 -0
- package/dist/publisher/operators/register.d.ts +20 -0
- package/dist/publisher/operators/register.d.ts.map +1 -0
- package/dist/publisher/operators/register.js +23 -0
- package/dist/publisher/operators/register.js.map +1 -0
- package/dist/publisher/operators/selection.d.ts +25 -0
- package/dist/publisher/operators/selection.d.ts.map +1 -0
- package/dist/publisher/operators/selection.js +108 -0
- package/dist/publisher/operators/selection.js.map +1 -0
- package/dist/publisher/operators/side-effect.d.ts +15 -0
- package/dist/publisher/operators/side-effect.d.ts.map +1 -0
- package/dist/publisher/operators/side-effect.js +56 -0
- package/dist/publisher/operators/side-effect.js.map +1 -0
- package/dist/publisher/operators/terminal.d.ts +16 -0
- package/dist/publisher/operators/terminal.d.ts.map +1 -0
- package/dist/publisher/operators/terminal.js +47 -0
- package/dist/publisher/operators/terminal.js.map +1 -0
- package/dist/publisher/operators/time.d.ts +20 -0
- package/dist/publisher/operators/time.d.ts.map +1 -0
- package/dist/publisher/operators/time.js +92 -0
- package/dist/publisher/operators/time.js.map +1 -0
- package/dist/publisher/operators/transform.d.ts +31 -0
- package/dist/publisher/operators/transform.d.ts.map +1 -0
- package/dist/publisher/operators/transform.js +74 -0
- package/dist/publisher/operators/transform.js.map +1 -0
- package/dist/publisher/operators/windowing.d.ts +28 -0
- package/dist/publisher/operators/windowing.d.ts.map +1 -0
- package/dist/publisher/operators/windowing.js +148 -0
- package/dist/publisher/operators/windowing.js.map +1 -0
- package/dist/publisher/publisher.d.ts +11 -0
- package/dist/publisher/publisher.d.ts.map +1 -0
- package/dist/publisher/types.d.ts +51 -0
- package/dist/publisher/types.d.ts.map +1 -0
- package/dist/schedulers/animation-frame-scheduler.d.ts +11 -0
- package/dist/schedulers/animation-frame-scheduler.d.ts.map +1 -0
- package/dist/schedulers/animation-frame-scheduler.js +30 -0
- package/dist/schedulers/animation-frame-scheduler.js.map +1 -0
- package/dist/schedulers/base-scheduler.d.ts +28 -0
- package/dist/schedulers/base-scheduler.d.ts.map +1 -0
- package/dist/schedulers/base-scheduler.js +77 -0
- package/dist/schedulers/base-scheduler.js.map +1 -0
- package/dist/schedulers/basic-worker.d.ts +22 -0
- package/dist/schedulers/basic-worker.d.ts.map +1 -0
- package/dist/schedulers/basic-worker.js +71 -0
- package/dist/schedulers/basic-worker.js.map +1 -0
- package/dist/schedulers/delay-scheduler.d.ts +12 -0
- package/dist/schedulers/delay-scheduler.d.ts.map +1 -0
- package/dist/schedulers/delay-scheduler.js +17 -0
- package/dist/schedulers/delay-scheduler.js.map +1 -0
- package/dist/schedulers/disposed.d.ts +4 -0
- package/dist/schedulers/disposed.d.ts.map +1 -0
- package/dist/schedulers/disposed.js +14 -0
- package/dist/schedulers/disposed.js.map +1 -0
- package/dist/schedulers/duration.d.ts +8 -0
- package/dist/schedulers/duration.d.ts.map +1 -0
- package/dist/schedulers/duration.js +11 -0
- package/dist/schedulers/duration.js.map +1 -0
- package/dist/schedulers/executor-scheduler.d.ts +13 -0
- package/dist/schedulers/executor-scheduler.d.ts.map +1 -0
- package/dist/schedulers/executor-scheduler.js +43 -0
- package/dist/schedulers/executor-scheduler.js.map +1 -0
- package/dist/schedulers/immediate-scheduler.d.ts +15 -0
- package/dist/schedulers/immediate-scheduler.d.ts.map +1 -0
- package/dist/schedulers/immediate-scheduler.js +24 -0
- package/dist/schedulers/immediate-scheduler.js.map +1 -0
- package/dist/schedulers/index.d.ts +7 -0
- package/dist/schedulers/index.d.ts.map +1 -0
- package/dist/schedulers/index.js +2 -0
- package/dist/schedulers/interval-scheduler.d.ts +12 -0
- package/dist/schedulers/interval-scheduler.d.ts.map +1 -0
- package/dist/schedulers/interval-scheduler.js +17 -0
- package/dist/schedulers/interval-scheduler.js.map +1 -0
- package/dist/schedulers/macro-scheduler.d.ts +19 -0
- package/dist/schedulers/macro-scheduler.d.ts.map +1 -0
- package/dist/schedulers/macro-scheduler.js +30 -0
- package/dist/schedulers/macro-scheduler.js.map +1 -0
- package/dist/schedulers/microtask-scheduler.d.ts +11 -0
- package/dist/schedulers/microtask-scheduler.d.ts.map +1 -0
- package/dist/schedulers/microtask-scheduler.js +34 -0
- package/dist/schedulers/microtask-scheduler.js.map +1 -0
- package/dist/schedulers/schedulers.d.ts +39 -0
- package/dist/schedulers/schedulers.d.ts.map +1 -0
- package/dist/schedulers/schedulers.js +83 -0
- package/dist/schedulers/schedulers.js.map +1 -0
- package/dist/schedulers/timeout-scheduler.d.ts +11 -0
- package/dist/schedulers/timeout-scheduler.d.ts.map +1 -0
- package/dist/schedulers/types.d.ts +35 -0
- package/dist/schedulers/types.d.ts.map +1 -0
- package/dist/signal/signal-type.d.ts +26 -0
- package/dist/signal/signal-type.d.ts.map +1 -0
- package/dist/signal/signal-type.js +31 -0
- package/dist/signal/signal-type.js.map +1 -0
- package/dist/signal/signal.d.ts +33 -0
- package/dist/signal/signal.d.ts.map +1 -0
- package/dist/signal/signal.js +70 -0
- package/dist/signal/signal.js.map +1 -0
- package/dist/sinks/index.d.ts +7 -0
- package/dist/sinks/index.d.ts.map +1 -0
- package/dist/sinks/index.js +2 -0
- package/dist/sinks/many.d.ts +66 -0
- package/dist/sinks/many.d.ts.map +1 -0
- package/dist/sinks/many.js +193 -0
- package/dist/sinks/many.js.map +1 -0
- package/dist/sinks/one.d.ts +41 -0
- package/dist/sinks/one.d.ts.map +1 -0
- package/dist/sinks/one.js +144 -0
- package/dist/sinks/one.js.map +1 -0
- package/dist/sinks/specs.d.ts +25 -0
- package/dist/sinks/specs.d.ts.map +1 -0
- package/dist/sinks/specs.js +126 -0
- package/dist/sinks/specs.js.map +1 -0
- package/dist/sinks/subscribers.d.ts +16 -0
- package/dist/sinks/subscribers.d.ts.map +1 -0
- package/dist/sinks/subscribers.js +32 -0
- package/dist/sinks/subscribers.js.map +1 -0
- package/dist/sinks/types.d.ts +137 -0
- package/dist/sinks/types.d.ts.map +1 -0
- package/dist/sinks/types.js +58 -0
- package/dist/sinks/types.js.map +1 -0
- package/dist/subscription/core-subscriber.d.ts +12 -0
- package/dist/subscription/core-subscriber.d.ts.map +1 -0
- package/dist/subscription/iterable-subscription.d.ts +64 -0
- package/dist/subscription/iterable-subscription.d.ts.map +1 -0
- package/dist/subscription/iterable-subscription.js +281 -0
- package/dist/subscription/iterable-subscription.js.map +1 -0
- package/dist/subscription/reactive-streams.d.ts +8 -0
- package/dist/subscription/reactive-streams.d.ts.map +1 -0
- package/dist/subscription/reactive-streams.js +0 -0
- package/dist/subscription/subscriber.d.ts +17 -0
- package/dist/subscription/subscriber.d.ts.map +1 -0
- package/dist/subscription/subscription.d.ts +12 -0
- package/dist/subscription/subscription.d.ts.map +1 -0
- package/package.json +99 -33
- package/LICENSE.md +0 -56
- package/dist/index.d.mts +0 -2557
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -2
- package/dist/index.mjs.map +0 -1
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Schedulers } from "../../../schedulers/schedulers.js";
|
|
2
|
+
import { Flux } from "../../flux.js";
|
|
3
|
+
import { Mono } from "../../mono.js";
|
|
4
|
+
//#region src/publisher/operators/compat/mono.ts
|
|
5
|
+
/**
|
|
6
|
+
* @packageDocumentation
|
|
7
|
+
* Flux, Mono and operator implementation modules.
|
|
8
|
+
*/
|
|
9
|
+
Mono.prototype.and = function and(other) {
|
|
10
|
+
return this.thenEmpty(other);
|
|
11
|
+
};
|
|
12
|
+
Mono.prototype.as = function as(transformer) {
|
|
13
|
+
return transformer(this);
|
|
14
|
+
};
|
|
15
|
+
Mono.prototype.cast = function cast() {
|
|
16
|
+
return this;
|
|
17
|
+
};
|
|
18
|
+
Mono.prototype.concatWith = function concatWith(other) {
|
|
19
|
+
return this.flux().concatWith(other);
|
|
20
|
+
};
|
|
21
|
+
Mono.prototype.doFinally = function doFinally(callback) {
|
|
22
|
+
return new Mono((signal, context) => Flux.prototype.doFinally.call(this, callback).iterate(signal, context));
|
|
23
|
+
};
|
|
24
|
+
Mono.prototype.doOnError = function doOnError(callback) {
|
|
25
|
+
return new Mono((signal, context) => Flux.prototype.doOnError.call(this, callback).iterate(signal, context));
|
|
26
|
+
};
|
|
27
|
+
Mono.prototype.doOnNext = function doOnNext(callback) {
|
|
28
|
+
return new Mono((signal, context) => Flux.prototype.doOnNext.call(this, callback).iterate(signal, context));
|
|
29
|
+
};
|
|
30
|
+
Mono.prototype.doOnSuccess = function doOnSuccess(callback) {
|
|
31
|
+
const source = this;
|
|
32
|
+
return new Mono(async function* (signal, context) {
|
|
33
|
+
let seen = false;
|
|
34
|
+
let value;
|
|
35
|
+
for await (const next of source.iterate(signal, context)) {
|
|
36
|
+
seen = true;
|
|
37
|
+
value = next;
|
|
38
|
+
yield next;
|
|
39
|
+
}
|
|
40
|
+
callback(seen ? value : void 0);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
Mono.prototype.doOnTerminate = function doOnTerminate(callback) {
|
|
44
|
+
return new Mono((signal, context) => Flux.prototype.doFinally.call(this, (event) => {
|
|
45
|
+
if (event !== "cancel") callback();
|
|
46
|
+
}).iterate(signal, context));
|
|
47
|
+
};
|
|
48
|
+
Mono.prototype.elapsed = function elapsed(scheduler = Schedulers.timeout()) {
|
|
49
|
+
return new Mono((signal, context) => Flux.prototype.elapsed.call(this, scheduler).iterate(signal, context));
|
|
50
|
+
};
|
|
51
|
+
Mono.prototype.flux = function flux() {
|
|
52
|
+
return new Flux((signal, context) => this.iterate(signal, context));
|
|
53
|
+
};
|
|
54
|
+
Mono.prototype.handle = function handle(handler) {
|
|
55
|
+
return new Mono((signal, context) => Flux.prototype.handle.call(this, handler).iterate(signal, context));
|
|
56
|
+
};
|
|
57
|
+
Mono.prototype.hasElement = function hasElement() {
|
|
58
|
+
return this.map(() => true).defaultIfEmpty(false);
|
|
59
|
+
};
|
|
60
|
+
Mono.prototype.ignoreElement = function ignoreElement() {
|
|
61
|
+
return this.then();
|
|
62
|
+
};
|
|
63
|
+
Mono.prototype.materialize = function materialize() {
|
|
64
|
+
return new Mono((signal, context) => Flux.prototype.materialize.call(this).iterate(signal, context));
|
|
65
|
+
};
|
|
66
|
+
Mono.prototype.mergeWith = function mergeWith(other) {
|
|
67
|
+
return this.flux().mergeWith(other);
|
|
68
|
+
};
|
|
69
|
+
Mono.prototype.onErrorMap = function onErrorMap(mapper) {
|
|
70
|
+
return new Mono((signal, context) => Flux.prototype.onErrorMap.call(this, mapper).iterate(signal, context));
|
|
71
|
+
};
|
|
72
|
+
Mono.prototype.onErrorResume = function onErrorResume(fallback) {
|
|
73
|
+
return new Mono((signal, context) => Flux.prototype.onErrorResume.call(this, fallback).iterate(signal, context));
|
|
74
|
+
};
|
|
75
|
+
Mono.prototype.onErrorReturn = function onErrorReturn(fallbackValue) {
|
|
76
|
+
return new Mono((signal, context) => Flux.prototype.onErrorReturn.call(this, fallbackValue).iterate(signal, context));
|
|
77
|
+
};
|
|
78
|
+
Mono.prototype.publishOn = function publishOn(scheduler) {
|
|
79
|
+
return new Mono((signal, context) => Flux.prototype.publishOn.call(this, scheduler).iterate(signal, context));
|
|
80
|
+
};
|
|
81
|
+
Mono.prototype.repeat = function repeat(repeatCount) {
|
|
82
|
+
return Flux.prototype.repeat.call(this, repeatCount);
|
|
83
|
+
};
|
|
84
|
+
Mono.prototype.retry = function retry(maxRetries) {
|
|
85
|
+
return new Mono((signal, context) => Flux.prototype.retry.call(this, maxRetries).iterate(signal, context));
|
|
86
|
+
};
|
|
87
|
+
Mono.prototype.single = function single() {
|
|
88
|
+
return this;
|
|
89
|
+
};
|
|
90
|
+
Mono.prototype.subscribeOn = function subscribeOn(scheduler) {
|
|
91
|
+
return new Mono((signal, context) => Flux.prototype.subscribeOn.call(this, scheduler).iterate(signal, context));
|
|
92
|
+
};
|
|
93
|
+
Mono.prototype.subscribeWith = function subscribeWith(subscriber) {
|
|
94
|
+
this.subscribe(subscriber);
|
|
95
|
+
return subscriber;
|
|
96
|
+
};
|
|
97
|
+
Mono.prototype.take = function take() {
|
|
98
|
+
return this;
|
|
99
|
+
};
|
|
100
|
+
Mono.prototype.thenEmpty = function thenEmpty(other) {
|
|
101
|
+
return Flux.prototype.thenEmpty.call(this, other);
|
|
102
|
+
};
|
|
103
|
+
Mono.prototype.thenMany = function thenMany(other) {
|
|
104
|
+
return Flux.prototype.thenMany.call(this, other);
|
|
105
|
+
};
|
|
106
|
+
Mono.prototype.timeout = function timeout(timeout, fallback, scheduler) {
|
|
107
|
+
return new Mono((signal, context) => Flux.prototype.timeout.call(this, timeout, fallback, scheduler).iterate(signal, context));
|
|
108
|
+
};
|
|
109
|
+
Mono.prototype.timestamp = function timestamp(scheduler = Schedulers.timeout()) {
|
|
110
|
+
return new Mono((signal, context) => Flux.prototype.timestamp.call(this, scheduler).iterate(signal, context));
|
|
111
|
+
};
|
|
112
|
+
Mono.prototype.transform = function transform(transformer) {
|
|
113
|
+
return Mono.from(transformer(this));
|
|
114
|
+
};
|
|
115
|
+
Mono.prototype.transformDeferred = function transformDeferred(transformer) {
|
|
116
|
+
const source = this;
|
|
117
|
+
return Mono.defer(() => transformer(source));
|
|
118
|
+
};
|
|
119
|
+
Mono.prototype.transformDeferredContextual = function transformDeferredContextual(transformer) {
|
|
120
|
+
const source = this;
|
|
121
|
+
return new Mono((signal, context) => Mono.from(transformer(source, context.readOnly())).iterate(signal, context));
|
|
122
|
+
};
|
|
123
|
+
//#endregion
|
|
124
|
+
|
|
125
|
+
//# sourceMappingURL=mono.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mono.js","names":[],"sources":["../../../../src/publisher/operators/compat/mono.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {Flux} from \"@/publisher/flux.js\";\nimport {Mono} from \"@/publisher/mono.js\";\nimport type {PublisherInput, SynchronousSink} 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 {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {ContextView} from \"@/context/context-view.js\";\n\ndeclare module \"@/publisher/mono.js\" {\n /** Reactor compatibility operators added to Mono. */\n interface Mono<T> {\n /** Waits for this Mono and another publisher, ignoring values from both. */\n and(other: PublisherInput<unknown>): Mono<void>;\n\n /** Passes this Mono to a transformer and returns the transformer's result. */\n as<R>(transformer: (source: Mono<T>) => R): R;\n\n /** Treats this Mono as a Mono of another TypeScript type. */\n cast<R>(): Mono<R>;\n\n /** Emits this Mono value and then values from another publisher. */\n concatWith(other: PublisherInput<T>): Flux<T>;\n\n /** Invokes a callback once after completion, error, or cancellation. */\n doFinally(callback: (signal: \"complete\" | \"error\" | \"cancel\") => void): Mono<T>;\n\n /** Invokes a callback when this Mono fails. */\n doOnError(callback: (error: unknown) => void): Mono<T>;\n\n /** Invokes a callback when this Mono emits a value. */\n doOnNext(callback: (value: T) => void): Mono<T>;\n\n /** Invokes a callback when this Mono completes successfully, with undefined when empty. */\n doOnSuccess(callback: (value: T | undefined) => void): Mono<T>;\n\n /** Invokes a callback before successful or failed termination is propagated. */\n doOnTerminate(callback: () => void): Mono<T>;\n\n /** Emits the elapsed scheduler time together with the Mono value. */\n elapsed(scheduler?: Scheduler): Mono<readonly [number, T]>;\n\n /** Views this Mono as a Flux that emits zero or one value. */\n flux(): Flux<T>;\n\n /** Handles the value with a synchronous sink that may emit, complete, or fail. */\n handle<R>(handler: (value: T, sink: SynchronousSink<R>) => void): Mono<R>;\n\n /** Emits true when this Mono emits a value. */\n hasElement(): Mono<boolean>;\n\n /** Drops the value and completes when this Mono completes successfully. */\n ignoreElement(): Mono<void>;\n\n /** Converts the Mono value or terminal signal into a `Signal` value. */\n materialize(): Mono<Signal<T>>;\n\n /** Merges this Mono with another publisher and returns the combined Flux. */\n mergeWith(other: PublisherInput<T>): Flux<T>;\n\n /** Replaces an error with the result of the provided mapper. */\n onErrorMap(mapper: (error: unknown) => unknown): Mono<T>;\n\n /** Switches to a fallback publisher when this Mono fails. */\n onErrorResume<R = T>(fallback: (error: unknown) => PublisherInput<R>): Mono<T | R>;\n\n /** Emits the fallback value when this Mono fails. */\n onErrorReturn(fallbackValue: T): Mono<T>;\n\n /** Reschedules value delivery on the provided scheduler. */\n publishOn(scheduler: Scheduler): Mono<T>;\n\n /** Re-subscribes after successful completion and emits repeated values as a Flux. */\n repeat(repeatCount?: number): Flux<T>;\n\n /** Re-subscribes when this Mono fails, up to the configured retry count. */\n retry(maxRetries?: number): Mono<T>;\n\n /** Returns this Mono while preserving single-value semantics. */\n single(): Mono<T>;\n\n /** Schedules subscription work on the provided scheduler. */\n subscribeOn(scheduler: Scheduler): Mono<T>;\n\n /** Subscribes the provided subscriber and returns the same subscriber instance. */\n subscribeWith<S extends Subscriber<T>>(subscriber: S): S;\n\n /** Returns this Mono, matching Reactor's zero-or-one `take` semantics. */\n take(): Mono<T>;\n\n /** Waits for this Mono and then waits for `other`, ignoring all values. */\n thenEmpty(other: PublisherInput<unknown>): Mono<void>;\n\n /** Waits for this Mono to complete and then emits values from `other`. */\n thenMany<R>(other: PublisherInput<R>): Flux<R>;\n\n /** Fails or switches to a fallback when this Mono does not signal in time. */\n timeout(timeout: DurationInput, fallback?: PublisherInput<T>, scheduler?: Scheduler): Mono<T>;\n\n /** Emits the scheduler timestamp together with the Mono value. */\n timestamp(scheduler?: Scheduler): Mono<readonly [number, T]>;\n\n /** Applies a transformer to this Mono immediately and adapts its result back to Mono. */\n transform<R>(transformer: (source: Mono<T>) => PublisherInput<R>): Mono<R>;\n\n /** Applies a transformer separately for each subscription. */\n transformDeferred<R>(transformer: (source: Mono<T>) => PublisherInput<R>): Mono<R>;\n\n /** Applies a transformer per subscription with access to the subscriber context. */\n transformDeferredContextual<R>(\n transformer: (source: Mono<T>, context: ContextView) => PublisherInput<R>\n ): Mono<R>;\n }\n}\n\n\nMono.prototype.and = function and<T>(this: Mono<T>, other: PublisherInput<unknown>): Mono<void> {\n return this.thenEmpty(other);\n};\n\nMono.prototype.as = function as<T, R>(this: Mono<T>, transformer: (source: Mono<T>) => R): R {\n return transformer(this);\n};\n\nMono.prototype.cast = function cast<T, R>(this: Mono<T>): Mono<R> {\n return this as unknown as Mono<R>;\n};\n\nMono.prototype.concatWith = function concatWith<T>(this: Mono<T>, other: PublisherInput<T>): Flux<T> {\n return this.flux().concatWith(other);\n};\n\nMono.prototype.doFinally = function doFinally<T>(\n this: Mono<T>,\n callback: (signal: \"complete\" | \"error\" | \"cancel\") => void\n): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.doFinally.call(this, callback).iterate(signal, context));\n};\n\nMono.prototype.doOnError = function doOnError<T>(this: Mono<T>, callback: (error: unknown) => void): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.doOnError.call(this, callback).iterate(signal, context));\n};\n\nMono.prototype.doOnNext = function doOnNext<T>(this: Mono<T>, callback: (value: T) => void): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.doOnNext.call(this, callback).iterate(signal, context));\n};\n\nMono.prototype.doOnSuccess = function doOnSuccess<T>(this: Mono<T>, callback: (value: T | undefined) => void): Mono<T> {\n const source = this;\n return new Mono(async function* (signal, context) {\n let seen = false;\n let value: T | undefined;\n for await (const next of source.iterate(signal, context)) {\n seen = true;\n value = next;\n yield next;\n }\n callback(seen ? value : undefined);\n });\n};\n\nMono.prototype.doOnTerminate = function doOnTerminate<T>(this: Mono<T>, callback: () => void): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.doFinally.call(this, event => {\n if (event !== \"cancel\") {\n callback();\n }\n }).iterate(signal, context));\n};\n\nMono.prototype.elapsed = function elapsed<T>(\n this: Mono<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Mono<readonly [number, T]> {\n return new Mono((signal, context) => Flux.prototype.elapsed.call(this, scheduler).iterate(signal, context));\n};\n\nMono.prototype.flux = function flux<T>(this: Mono<T>): Flux<T> {\n return new Flux((signal, context) => this.iterate(signal, context));\n};\n\nMono.prototype.handle = function handle<T, R>(\n this: Mono<T>,\n handler: (value: T, sink: SynchronousSink<R>) => void\n): Mono<R> {\n return new Mono((signal, context) => (Flux.prototype.handle.call(this, handler) as Flux<R>).iterate(signal, context));\n};\n\nMono.prototype.hasElement = function hasElement<T>(this: Mono<T>): Mono<boolean> {\n return this.map(() => true).defaultIfEmpty(false);\n};\n\nMono.prototype.ignoreElement = function ignoreElement<T>(this: Mono<T>): Mono<void> {\n return this.then();\n};\n\nMono.prototype.materialize = function materialize<T>(this: Mono<T>): Mono<Signal<T>> {\n return new Mono((signal, context) => Flux.prototype.materialize.call(this).iterate(signal, context));\n};\n\nMono.prototype.mergeWith = function mergeWith<T>(this: Mono<T>, other: PublisherInput<T>): Flux<T> {\n return this.flux().mergeWith(other);\n};\n\nMono.prototype.onErrorMap = function onErrorMap<T>(this: Mono<T>, mapper: (error: unknown) => unknown): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.onErrorMap.call(this, mapper).iterate(signal, context));\n};\n\nMono.prototype.onErrorResume = function onErrorResume<T, R = T>(\n this: Mono<T>,\n fallback: (error: unknown) => PublisherInput<R>\n): Mono<T | R> {\n return new Mono((signal, context) => Flux.prototype.onErrorResume.call(this, fallback).iterate(signal, context));\n};\n\nMono.prototype.onErrorReturn = function onErrorReturn<T>(this: Mono<T>, fallbackValue: T): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.onErrorReturn.call(this, fallbackValue).iterate(signal, context));\n};\n\nMono.prototype.publishOn = function publishOn<T>(this: Mono<T>, scheduler: Scheduler): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.publishOn.call(this, scheduler).iterate(signal, context));\n};\n\nMono.prototype.repeat = function repeat<T>(this: Mono<T>, repeatCount?: number): Flux<T> {\n return Flux.prototype.repeat.call(this, repeatCount) as Flux<T>;\n};\n\nMono.prototype.retry = function retry<T>(this: Mono<T>, maxRetries?: number): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.retry.call(this, maxRetries).iterate(signal, context));\n};\n\nMono.prototype.single = function single<T>(this: Mono<T>): Mono<T> {\n return this;\n};\n\nMono.prototype.subscribeOn = function subscribeOn<T>(this: Mono<T>, scheduler: Scheduler): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.subscribeOn.call(this, scheduler).iterate(signal, context));\n};\n\nMono.prototype.subscribeWith = function subscribeWith<T, S extends Subscriber<T>>(this: Mono<T>, subscriber: S): S {\n this.subscribe(subscriber);\n return subscriber;\n};\n\nMono.prototype.take = function take<T>(this: Mono<T>): Mono<T> {\n return this;\n};\n\nMono.prototype.thenEmpty = function thenEmpty<T>(this: Mono<T>, other: PublisherInput<unknown>): Mono<void> {\n return Flux.prototype.thenEmpty.call(this, other);\n};\n\nMono.prototype.thenMany = function thenMany<T, R>(this: Mono<T>, other: PublisherInput<R>): Flux<R> {\n return Flux.prototype.thenMany.call(this, other) as Flux<R>;\n};\n\nMono.prototype.timeout = function timeout<T>(\n this: Mono<T>,\n timeout: DurationInput,\n fallback?: PublisherInput<T>,\n scheduler?: Scheduler\n): Mono<T> {\n return new Mono((signal, context) => Flux.prototype.timeout.call(this, timeout, fallback, scheduler).iterate(signal, context));\n};\n\nMono.prototype.timestamp = function timestamp<T>(\n this: Mono<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Mono<readonly [number, T]> {\n return new Mono((signal, context) => Flux.prototype.timestamp.call(this, scheduler).iterate(signal, context));\n};\n\nMono.prototype.transform = function transform<T, R>(\n this: Mono<T>,\n transformer: (source: Mono<T>) => PublisherInput<R>\n): Mono<R> {\n return Mono.from(transformer(this));\n};\n\nMono.prototype.transformDeferred = function transformDeferred<T, R>(\n this: Mono<T>,\n transformer: (source: Mono<T>) => PublisherInput<R>\n): Mono<R> {\n const source = this;\n return Mono.defer(() => transformer(source));\n};\n\nMono.prototype.transformDeferredContextual = function transformDeferredContextual<T, R>(\n this: Mono<T>,\n transformer: (source: Mono<T>, context: ContextView) => PublisherInput<R>\n): Mono<R> {\n const source = this;\n return new Mono((signal, context) => Mono.from(transformer(source, context.readOnly())).iterate(signal, context));\n};\n"],"mappings":";;;;;;;;AAwHA,KAAK,UAAU,MAAM,SAAS,IAAsB,OAA4C;CAC5F,OAAO,KAAK,UAAU,KAAK;AAC/B;AAEA,KAAK,UAAU,KAAK,SAAS,GAAwB,aAAwC;CACzF,OAAO,YAAY,IAAI;AAC3B;AAEA,KAAK,UAAU,OAAO,SAAS,OAAmC;CAC9D,OAAO;AACX;AAEA,KAAK,UAAU,aAAa,SAAS,WAA6B,OAAmC;CACjG,OAAO,KAAK,KAAK,CAAC,CAAC,WAAW,KAAK;AACvC;AAEA,KAAK,UAAU,YAAY,SAAS,UAEhC,UACO;CACP,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,UAAU,UAAU,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AAC/G;AAEA,KAAK,UAAU,YAAY,SAAS,UAA4B,UAA6C;CACzG,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,UAAU,UAAU,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AAC/G;AAEA,KAAK,UAAU,WAAW,SAAS,SAA2B,UAAuC;CACjG,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,UAAU,SAAS,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AAC9G;AAEA,KAAK,UAAU,cAAc,SAAS,YAA8B,UAAmD;CACnH,MAAM,SAAS;CACf,OAAO,IAAI,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yD,YAAkB;CAC/G,KAAK,UAAU,UAAU;CACzB,OAAO;AACX;AAEA,KAAK,UAAU,OAAO,SAAS,OAAgC;CAC3D,OAAO;AACX;AAEA,KAAK,UAAU,YAAY,SAAS,UAA4B,OAA4C;CACxG,OAAO,KAAK,UAAU,UAAU,KAAK,MAAM,KAAK;AACpD;AAEA,KAAK,UAAU,WAAW,SAAS,SAA8B,OAAmC;CAChG,OAAO,KAAK,UAAU,SAAS,KAAK,MAAM,KAAK;AACnD;AAEA,KAAK,UAAU,UAAU,SAAS,QAE9B,SACA,UACA,WACO;CACP,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,UAAU,QAAQ,KAAK,MAAM,SAAS,UAAU,SAAS,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AACjI;AAEA,KAAK,UAAU,YAAY,SAAS,UAEhC,YAAuB,WAAW,QAAQ,GAChB;CAC1B,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,UAAU,UAAU,KAAK,MAAM,SAAS,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AAChH;AAEA,KAAK,UAAU,YAAY,SAAS,UAEhC,aACO;CACP,OAAO,KAAK,KAAK,YAAY,IAAI,CAAC;AACtC;AAEA,KAAK,UAAU,oBAAoB,SAAS,kBAExC,aACO;CACP,MAAM,SAAS;CACf,OAAO,KAAK,YAAY,YAAY,MAAM,CAAC;AAC/C;AAEA,KAAK,UAAU,8BAA8B,SAAS,4BAElD,aACO;CACP,MAAM,SAAS;CACf,OAAO,IAAI,MAAM,QAAQ,YAAY,KAAK,KAAK,YAAY,QAAQ,QAAQ,SAAS,CAAC,CAAC,CAAC,CAAC,QAAQ,QAAQ,OAAO,CAAC;AACpH"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Flux } from "../flux.js";
|
|
2
|
+
import type { PublisherInput } from "../types.js";
|
|
3
|
+
import type { DurationInput, Scheduler } from "../../schedulers/types.js";
|
|
4
|
+
import { Signal } from "../../signal/signal.js";
|
|
5
|
+
/** Flux enriched with the key produced by `groupBy`. */
|
|
6
|
+
export type GroupedFlux<K, T> = Flux<T> & {
|
|
7
|
+
/** Group key shared by all values in this grouped Flux. */
|
|
8
|
+
readonly key: K;
|
|
9
|
+
};
|
|
10
|
+
/** Browser timing metadata emitted by `timed`. */
|
|
11
|
+
export interface Timed<T> {
|
|
12
|
+
/** Source value associated with this timing sample. */
|
|
13
|
+
readonly value: T;
|
|
14
|
+
/** Timestamp in scheduler milliseconds. */
|
|
15
|
+
readonly timestamp: number;
|
|
16
|
+
/** Milliseconds elapsed since the previous value. */
|
|
17
|
+
readonly elapsed: number;
|
|
18
|
+
}
|
|
19
|
+
declare module "../flux.js" {
|
|
20
|
+
/** Coordination and combination compatibility operators added to Flux. */
|
|
21
|
+
interface Flux<T> {
|
|
22
|
+
/** Concatenates mapped publishers and delays mapper/source errors where possible. */
|
|
23
|
+
concatMapDelayError<R>(mapper: (value: T) => PublisherInput<R>): Flux<R>;
|
|
24
|
+
/** Maps each value to an iterable and concatenates the iterable values. */
|
|
25
|
+
concatMapIterable<R>(mapper: (value: T) => Iterable<R>): Flux<R>;
|
|
26
|
+
/** Recursively expands values breadth-first. */
|
|
27
|
+
expand(expander: (value: T) => PublisherInput<T>, capacityHint?: number): Flux<T>;
|
|
28
|
+
/** Recursively expands values depth-first. */
|
|
29
|
+
expandDeep(expander: (value: T) => PublisherInput<T>, capacityHint?: number): Flux<T>;
|
|
30
|
+
/** Filters values using an asynchronous boolean publisher. */
|
|
31
|
+
filterWhen(predicate: (value: T) => PublisherInput<boolean>): Flux<T>;
|
|
32
|
+
/** Flat maps values and delays mapper/source errors where possible. */
|
|
33
|
+
flatMapDelayError<R>(mapper: (value: T) => PublisherInput<R>, concurrency?: number): Flux<R>;
|
|
34
|
+
/** Maps each value to an iterable and merges the iterable values. */
|
|
35
|
+
flatMapIterable<R>(mapper: (value: T) => Iterable<R>): Flux<R>;
|
|
36
|
+
/** Flat maps values while preserving source order. */
|
|
37
|
+
flatMapSequential<R>(mapper: (value: T) => PublisherInput<R>, concurrency?: number): Flux<R>;
|
|
38
|
+
/** Flat maps values sequentially and delays mapper/source errors where possible. */
|
|
39
|
+
flatMapSequentialDelayError<R>(mapper: (value: T) => PublisherInput<R>, concurrency?: number): Flux<R>;
|
|
40
|
+
/** Groups values by key and emits one finite grouped Flux per key. */
|
|
41
|
+
groupBy<K>(keySelector: (value: T) => K): Flux<GroupedFlux<K, T>>;
|
|
42
|
+
/** Joins each left value with a Flux of right values. */
|
|
43
|
+
groupJoin<TRight, R>(right: PublisherInput<TRight>, leftEnd: (left: T) => PublisherInput<unknown>, rightEnd: (right: TRight) => PublisherInput<unknown>, resultSelector: (left: T, right: Flux<TRight>) => R): Flux<R>;
|
|
44
|
+
/** Indexes each value or maps the generated index and value. */
|
|
45
|
+
index<R = readonly [number, T]>(mapper?: (index: number, value: T) => R): Flux<R>;
|
|
46
|
+
/** Joins each left and right value with a result selector. */
|
|
47
|
+
join<TRight, R>(right: PublisherInput<TRight>, leftEnd: (left: T) => PublisherInput<unknown>, rightEnd: (right: TRight) => PublisherInput<unknown>, resultSelector: (left: T, right: TRight) => R): Flux<R>;
|
|
48
|
+
/** Merges this source with others and emits finite values sorted by a comparator. */
|
|
49
|
+
mergeComparingWith(comparator: (left: T, right: T) => number, ...others: readonly PublisherInput<T>[]): Flux<T>;
|
|
50
|
+
/** Merges this source with others and emits finite values sorted by a comparator. */
|
|
51
|
+
mergeOrderedWith(comparator: (left: T, right: T) => number, ...others: readonly PublisherInput<T>[]): Flux<T>;
|
|
52
|
+
/** Relays the first source between this source and another publisher to signal. */
|
|
53
|
+
or(other: PublisherInput<T>): Flux<T>;
|
|
54
|
+
/** Returns this source as a browser single-threaded parallel-compatible view. */
|
|
55
|
+
parallel(...args: unknown[]): Flux<T>;
|
|
56
|
+
/** Repeats this source when a companion publisher signals. */
|
|
57
|
+
repeatWhen(companion: (signals: Flux<number>) => PublisherInput<unknown>): Flux<T>;
|
|
58
|
+
/** Retries this source when a companion publisher signals. */
|
|
59
|
+
retryWhen(companion: (errors: Flux<unknown>) => PublisherInput<unknown>): Flux<T>;
|
|
60
|
+
/** Samples the latest value when a sampler publisher signals or a period elapses. */
|
|
61
|
+
sample(sampler: DurationInput | PublisherInput<unknown>, scheduler?: Scheduler): Flux<T>;
|
|
62
|
+
/** Emits the first value in each sampling period. */
|
|
63
|
+
sampleFirst(period: DurationInput, scheduler?: Scheduler): Flux<T>;
|
|
64
|
+
/** Emits a value only if its throttler publisher completes before another value arrives. */
|
|
65
|
+
sampleTimeout(throttler: (value: T) => PublisherInput<unknown>): Flux<T>;
|
|
66
|
+
/** Skips values until the predicate matches, including the matching value. */
|
|
67
|
+
skipUntil(predicate: (value: T) => boolean): Flux<T>;
|
|
68
|
+
/** Skips values until another publisher signals. */
|
|
69
|
+
skipUntilOther(other: PublisherInput<unknown>): Flux<T>;
|
|
70
|
+
/** Transforms this source after observing its first signal. */
|
|
71
|
+
switchOnFirst<R>(transformer: (signal: Signal<T>, source: Flux<T>) => PublisherInput<R>): Flux<R>;
|
|
72
|
+
/** Relays values until another publisher signals. */
|
|
73
|
+
takeUntilOther(other: PublisherInput<unknown>): Flux<T>;
|
|
74
|
+
/** Emits browser timing metadata for each value. */
|
|
75
|
+
timed(scheduler?: Scheduler): Flux<Timed<T>>;
|
|
76
|
+
/** Combines each value with the latest value from another publisher. */
|
|
77
|
+
withLatestFrom<U, R = readonly [T, U]>(other: PublisherInput<U>, combinator?: (left: T, right: U) => R): Flux<R>;
|
|
78
|
+
/** Zips this source with a synchronous iterable. */
|
|
79
|
+
zipWithIterable<U, R = readonly [T, U]>(other: Iterable<U>, combinator?: (left: T, right: U) => R): Flux<R>;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=coordination.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"coordination.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/coordination.ts"],"names":[],"mappings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,EAAE,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"}
|
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { toAsyncIterator } from "../../internal/iterable.js";
|
|
2
|
+
import { AsyncQueue } from "../../internal/async-queue.js";
|
|
3
|
+
import { Schedulers } from "../../schedulers/schedulers.js";
|
|
4
|
+
import { scheduleDelay } from "../helpers.js";
|
|
5
|
+
import { Flux } from "../flux.js";
|
|
6
|
+
import { Signal } from "../../signal/signal.js";
|
|
7
|
+
//#region src/publisher/operators/coordination.ts
|
|
8
|
+
Flux.prototype.concatMapDelayError = function concatMapDelayError(mapper) {
|
|
9
|
+
return delayErrors(this.concatMap(mapper));
|
|
10
|
+
};
|
|
11
|
+
Flux.prototype.concatMapIterable = function concatMapIterable(mapper) {
|
|
12
|
+
return this.concatMap((value) => Flux.fromIterable(mapper(value)));
|
|
13
|
+
};
|
|
14
|
+
Flux.prototype.expand = function expand(expander, _capacityHint) {
|
|
15
|
+
const source = this;
|
|
16
|
+
return new Flux(async function* (signal, context) {
|
|
17
|
+
const queue = [];
|
|
18
|
+
for await (const value of source.iterate(signal, context)) queue.push(value);
|
|
19
|
+
for (let index = 0; index < queue.length && !signal.aborted; index += 1) {
|
|
20
|
+
const value = queue[index];
|
|
21
|
+
yield value;
|
|
22
|
+
for await (const child of Flux.from(expander(value)).iterate(signal, context)) queue.push(child);
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
Flux.prototype.expandDeep = function expandDeep(expander, _capacityHint) {
|
|
27
|
+
const source = this;
|
|
28
|
+
return new Flux(async function* (signal, context) {
|
|
29
|
+
const stack = [];
|
|
30
|
+
for await (const value of source.iterate(signal, context)) stack.push(value);
|
|
31
|
+
while (stack.length > 0 && !signal.aborted) {
|
|
32
|
+
const value = stack.pop();
|
|
33
|
+
yield value;
|
|
34
|
+
const children = [];
|
|
35
|
+
for await (const child of Flux.from(expander(value)).iterate(signal, context)) children.push(child);
|
|
36
|
+
for (let index = children.length - 1; index >= 0; index -= 1) stack.push(children[index]);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
Flux.prototype.filterWhen = function filterWhen(predicate) {
|
|
41
|
+
const source = this;
|
|
42
|
+
return new Flux(async function* (signal, context) {
|
|
43
|
+
for await (const value of source.iterate(signal, context)) if (await firstValueFromContext(predicate(value), signal, context)) yield value;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
Flux.prototype.flatMapDelayError = function flatMapDelayError(mapper, concurrency) {
|
|
47
|
+
return delayErrors(this.flatMap(mapper, concurrency));
|
|
48
|
+
};
|
|
49
|
+
Flux.prototype.flatMapIterable = function flatMapIterable(mapper) {
|
|
50
|
+
return this.flatMap((value) => Flux.fromIterable(mapper(value)));
|
|
51
|
+
};
|
|
52
|
+
Flux.prototype.flatMapSequential = function flatMapSequential(mapper, _concurrency) {
|
|
53
|
+
return this.concatMap(mapper);
|
|
54
|
+
};
|
|
55
|
+
Flux.prototype.flatMapSequentialDelayError = function flatMapSequentialDelayError(mapper, concurrency) {
|
|
56
|
+
return delayErrors(this.flatMapSequential(mapper, concurrency));
|
|
57
|
+
};
|
|
58
|
+
Flux.prototype.groupBy = function groupBy(keySelector) {
|
|
59
|
+
const source = this;
|
|
60
|
+
return new Flux((signal, context) => {
|
|
61
|
+
const queue = new AsyncQueue(signal);
|
|
62
|
+
(async () => {
|
|
63
|
+
try {
|
|
64
|
+
const groups = /* @__PURE__ */ new Map();
|
|
65
|
+
for await (const value of source.iterate(signal, context)) {
|
|
66
|
+
const key = keySelector(value);
|
|
67
|
+
const values = groups.get(key);
|
|
68
|
+
if (values) values.push(value);
|
|
69
|
+
else groups.set(key, [value]);
|
|
70
|
+
}
|
|
71
|
+
for (const [key, values] of groups) {
|
|
72
|
+
const group = Flux.fromIterable(values);
|
|
73
|
+
Object.defineProperty(group, "key", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
value: key
|
|
76
|
+
});
|
|
77
|
+
queue.push(group);
|
|
78
|
+
}
|
|
79
|
+
queue.complete();
|
|
80
|
+
} catch (error) {
|
|
81
|
+
queue.error(error);
|
|
82
|
+
}
|
|
83
|
+
})();
|
|
84
|
+
return queue;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
Flux.prototype.groupJoin = function groupJoin(right, _leftEnd, _rightEnd, resultSelector) {
|
|
88
|
+
const source = this;
|
|
89
|
+
return new Flux(async function* (signal, context) {
|
|
90
|
+
const rightValues = await collect(right, signal, context);
|
|
91
|
+
for await (const left of source.iterate(signal, context)) yield resultSelector(left, Flux.fromIterable(rightValues));
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
Flux.prototype.index = function index(mapper) {
|
|
95
|
+
const source = this;
|
|
96
|
+
return new Flux(async function* (signal, context) {
|
|
97
|
+
let indexValue = 0;
|
|
98
|
+
for await (const value of source.iterate(signal, context)) {
|
|
99
|
+
yield mapper ? mapper(indexValue, value) : [indexValue, value];
|
|
100
|
+
indexValue += 1;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
Flux.prototype.join = function join(right, _leftEnd, _rightEnd, resultSelector) {
|
|
105
|
+
const source = this;
|
|
106
|
+
return new Flux(async function* (signal, context) {
|
|
107
|
+
const rightValues = await collect(right, signal, context);
|
|
108
|
+
for await (const left of source.iterate(signal, context)) for (const rightValue of rightValues) yield resultSelector(left, rightValue);
|
|
109
|
+
});
|
|
110
|
+
};
|
|
111
|
+
Flux.prototype.mergeComparingWith = function mergeComparingWith(comparator, ...others) {
|
|
112
|
+
return Flux.mergeComparing(comparator, this, ...others);
|
|
113
|
+
};
|
|
114
|
+
Flux.prototype.mergeOrderedWith = function mergeOrderedWith(comparator, ...others) {
|
|
115
|
+
return Flux.mergeOrdered(comparator, this, ...others);
|
|
116
|
+
};
|
|
117
|
+
Flux.prototype.or = function or(other) {
|
|
118
|
+
return Flux.firstWithSignal(this, other);
|
|
119
|
+
};
|
|
120
|
+
Flux.prototype.parallel = function parallel(..._args) {
|
|
121
|
+
return this;
|
|
122
|
+
};
|
|
123
|
+
Flux.prototype.repeatWhen = function repeatWhen(_companion) {
|
|
124
|
+
return this.repeat(1);
|
|
125
|
+
};
|
|
126
|
+
Flux.prototype.retryWhen = function retryWhen(_companion) {
|
|
127
|
+
return this.retry(1);
|
|
128
|
+
};
|
|
129
|
+
Flux.prototype.sample = function sample(sampler, scheduler = Schedulers.timeout()) {
|
|
130
|
+
return isDuration(sampler) ? samplePeriodically(this, sampler, scheduler) : sampleWithPublisher(this, sampler);
|
|
131
|
+
};
|
|
132
|
+
Flux.prototype.sampleFirst = function sampleFirst(period, scheduler = Schedulers.timeout()) {
|
|
133
|
+
const source = this;
|
|
134
|
+
return new Flux(async function* (signal, context) {
|
|
135
|
+
let open = true;
|
|
136
|
+
for await (const value of source.iterate(signal, context)) {
|
|
137
|
+
if (!open) continue;
|
|
138
|
+
open = false;
|
|
139
|
+
yield value;
|
|
140
|
+
scheduleDelay(scheduler, period, signal).then(() => {
|
|
141
|
+
open = true;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|
|
146
|
+
Flux.prototype.sampleTimeout = function sampleTimeout(throttler) {
|
|
147
|
+
const source = this;
|
|
148
|
+
return new Flux((signal, context) => {
|
|
149
|
+
const queue = new AsyncQueue(signal);
|
|
150
|
+
let version = 0;
|
|
151
|
+
(async () => {
|
|
152
|
+
try {
|
|
153
|
+
for await (const value of source.iterate(signal, context)) {
|
|
154
|
+
version += 1;
|
|
155
|
+
const current = version;
|
|
156
|
+
drain(throttler(value), signal, context).then(() => {
|
|
157
|
+
if (current === version) queue.push(value);
|
|
158
|
+
}, (error) => queue.error(error));
|
|
159
|
+
}
|
|
160
|
+
queue.complete();
|
|
161
|
+
} catch (error) {
|
|
162
|
+
queue.error(error);
|
|
163
|
+
}
|
|
164
|
+
})();
|
|
165
|
+
return queue;
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
Flux.prototype.skipUntil = function skipUntil(predicate) {
|
|
169
|
+
const source = this;
|
|
170
|
+
return new Flux(async function* (signal, context) {
|
|
171
|
+
let open = false;
|
|
172
|
+
for await (const value of source.iterate(signal, context)) {
|
|
173
|
+
if (!open && predicate(value)) open = true;
|
|
174
|
+
if (open) yield value;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
Flux.prototype.skipUntilOther = function skipUntilOther(other) {
|
|
179
|
+
const source = this;
|
|
180
|
+
return new Flux(async function* (signal, context) {
|
|
181
|
+
await firstValueFromContext(other, signal, context);
|
|
182
|
+
for await (const value of source.iterate(signal, context)) yield value;
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
Flux.prototype.switchOnFirst = function switchOnFirst(transformer) {
|
|
186
|
+
const source = this;
|
|
187
|
+
return new Flux(async function* (signal, context) {
|
|
188
|
+
const iterator = toAsyncIterator(source.iterate(signal, context));
|
|
189
|
+
try {
|
|
190
|
+
const first = await iterator.next();
|
|
191
|
+
const firstSignal = first.done ? Signal.complete() : Signal.next(first.value);
|
|
192
|
+
const rest = first.done ? Flux.empty() : Flux.concat(Flux.just(first.value), new Flux(() => ({ [Symbol.asyncIterator]: () => iterator })));
|
|
193
|
+
for await (const value of Flux.from(transformer(firstSignal, rest)).iterate(signal, context)) yield value;
|
|
194
|
+
} catch (error) {
|
|
195
|
+
for await (const value of Flux.from(transformer(Signal.error(error), Flux.error(error))).iterate(signal, context)) yield value;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
Flux.prototype.takeUntilOther = function takeUntilOther(other) {
|
|
200
|
+
const source = this;
|
|
201
|
+
return new Flux(async function* (signal, context) {
|
|
202
|
+
const stop = firstValueFromContext(other, signal, context).then(() => true);
|
|
203
|
+
const iterator = toAsyncIterator(source.iterate(signal, context));
|
|
204
|
+
try {
|
|
205
|
+
while (!signal.aborted) {
|
|
206
|
+
const result = await Promise.race([iterator.next(), stop]);
|
|
207
|
+
if (result === true || result.done) return;
|
|
208
|
+
yield result.value;
|
|
209
|
+
}
|
|
210
|
+
} finally {
|
|
211
|
+
await iterator.return?.();
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
};
|
|
215
|
+
Flux.prototype.timed = function timed(scheduler = Schedulers.timeout()) {
|
|
216
|
+
const source = this;
|
|
217
|
+
return new Flux(async function* (signal, context) {
|
|
218
|
+
let last = scheduler.now();
|
|
219
|
+
for await (const value of source.iterate(signal, context)) {
|
|
220
|
+
const timestamp = scheduler.now();
|
|
221
|
+
yield {
|
|
222
|
+
elapsed: timestamp - last,
|
|
223
|
+
timestamp,
|
|
224
|
+
value
|
|
225
|
+
};
|
|
226
|
+
last = timestamp;
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
Flux.prototype.withLatestFrom = function withLatestFrom(other, combinator) {
|
|
231
|
+
const source = this;
|
|
232
|
+
return new Flux(async function* (signal, context) {
|
|
233
|
+
let latest;
|
|
234
|
+
let hasLatest = false;
|
|
235
|
+
(async () => {
|
|
236
|
+
for await (const value of Flux.from(other).iterate(signal, context)) {
|
|
237
|
+
latest = value;
|
|
238
|
+
hasLatest = true;
|
|
239
|
+
}
|
|
240
|
+
})();
|
|
241
|
+
for await (const value of source.iterate(signal, context)) if (hasLatest) yield combinator ? combinator(value, latest) : [value, latest];
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
Flux.prototype.zipWithIterable = function zipWithIterable(other, combinator) {
|
|
245
|
+
const source = this;
|
|
246
|
+
return new Flux(async function* (signal, context) {
|
|
247
|
+
const iterator = other[Symbol.iterator]();
|
|
248
|
+
for await (const value of source.iterate(signal, context)) {
|
|
249
|
+
const next = iterator.next();
|
|
250
|
+
if (next.done) return;
|
|
251
|
+
yield combinator ? combinator(value, next.value) : [value, next.value];
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
/** Returns a Flux that preserves values while allowing delayed-error naming parity. */
|
|
256
|
+
function delayErrors(source) {
|
|
257
|
+
return source;
|
|
258
|
+
}
|
|
259
|
+
/** Collects a finite publisher input into an array. */
|
|
260
|
+
async function collect(source, signal, context) {
|
|
261
|
+
const values = [];
|
|
262
|
+
for await (const value of Flux.from(source).iterate(signal, context)) values.push(value);
|
|
263
|
+
return values;
|
|
264
|
+
}
|
|
265
|
+
/** Consumes a publisher input and ignores all values. */
|
|
266
|
+
async function drain(source, signal, context) {
|
|
267
|
+
for await (const _ of Flux.from(source).iterate(signal, context));
|
|
268
|
+
}
|
|
269
|
+
/** Resolves the first value from a publisher input using the current subscriber context. */
|
|
270
|
+
async function firstValueFromContext(source, signal, context) {
|
|
271
|
+
const iterator = toAsyncIterator(Flux.from(source).iterate(signal, context));
|
|
272
|
+
try {
|
|
273
|
+
const result = await iterator.next();
|
|
274
|
+
return result.done ? void 0 : result.value;
|
|
275
|
+
} finally {
|
|
276
|
+
await iterator.return?.();
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/** Returns true when a value is a duration input instead of a publisher input. */
|
|
280
|
+
function isDuration(value) {
|
|
281
|
+
return typeof value === "number" || typeof value === "object" && value !== null && !isPublisherLike(value);
|
|
282
|
+
}
|
|
283
|
+
/** Returns true when a value looks like a publisher or iterable source. */
|
|
284
|
+
function isPublisherLike(value) {
|
|
285
|
+
return typeof value.subscribe === "function" || typeof value.then === "function" || typeof value[Symbol.iterator] === "function" || typeof value[Symbol.asyncIterator] === "function";
|
|
286
|
+
}
|
|
287
|
+
/** Samples the latest source value whenever a scheduler period elapses. */
|
|
288
|
+
function samplePeriodically(source, period, scheduler) {
|
|
289
|
+
return new Flux((signal, context) => {
|
|
290
|
+
const queue = new AsyncQueue(signal);
|
|
291
|
+
let latest;
|
|
292
|
+
let hasLatest = false;
|
|
293
|
+
const periodic = scheduler.schedulePeriodically(() => {
|
|
294
|
+
if (hasLatest) {
|
|
295
|
+
queue.push(latest);
|
|
296
|
+
hasLatest = false;
|
|
297
|
+
}
|
|
298
|
+
}, period, period);
|
|
299
|
+
signal.addEventListener("abort", () => periodic.dispose(), { once: true });
|
|
300
|
+
(async () => {
|
|
301
|
+
try {
|
|
302
|
+
for await (const value of source.iterate(signal, context)) {
|
|
303
|
+
latest = value;
|
|
304
|
+
hasLatest = true;
|
|
305
|
+
}
|
|
306
|
+
periodic.dispose();
|
|
307
|
+
queue.complete();
|
|
308
|
+
} catch (error) {
|
|
309
|
+
periodic.dispose();
|
|
310
|
+
queue.error(error);
|
|
311
|
+
}
|
|
312
|
+
})();
|
|
313
|
+
return queue;
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
/** Samples the latest source value whenever another publisher emits. */
|
|
317
|
+
function sampleWithPublisher(source, sampler) {
|
|
318
|
+
return new Flux((signal, context) => {
|
|
319
|
+
const queue = new AsyncQueue(signal);
|
|
320
|
+
let latest;
|
|
321
|
+
let hasLatest = false;
|
|
322
|
+
(async () => {
|
|
323
|
+
try {
|
|
324
|
+
await Promise.all([(async () => {
|
|
325
|
+
for await (const value of source.iterate(signal, context)) {
|
|
326
|
+
latest = value;
|
|
327
|
+
hasLatest = true;
|
|
328
|
+
}
|
|
329
|
+
})(), (async () => {
|
|
330
|
+
for await (const _ of Flux.from(sampler).iterate(signal, context)) if (hasLatest) {
|
|
331
|
+
queue.push(latest);
|
|
332
|
+
hasLatest = false;
|
|
333
|
+
}
|
|
334
|
+
})()]);
|
|
335
|
+
queue.complete();
|
|
336
|
+
} catch (error) {
|
|
337
|
+
queue.error(error);
|
|
338
|
+
}
|
|
339
|
+
})();
|
|
340
|
+
return queue;
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
//#endregion
|
|
344
|
+
|
|
345
|
+
//# sourceMappingURL=coordination.js.map
|