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,373 @@
|
|
|
1
|
+
import { EMPTY_ITERABLE, closeAsyncIterator, isAsyncIterable, neverIterable, toAsyncIterator } from "../internal/iterable.js";
|
|
2
|
+
import { CompositeError } from "../errors/classes.js";
|
|
3
|
+
import { throwIfNullish } from "../errors/helpers.js";
|
|
4
|
+
import { firstValueFrom, raceWithAbort } from "../internal/abort.js";
|
|
5
|
+
import { AsyncQueue } from "../internal/async-queue.js";
|
|
6
|
+
import { Schedulers } from "../schedulers/schedulers.js";
|
|
7
|
+
import { addCancelCallback, runCancelCallbacks, scheduleDelay } from "./helpers.js";
|
|
8
|
+
import { Flux } from "./flux.js";
|
|
9
|
+
//#region src/publisher/mono.ts
|
|
10
|
+
/** Zero-or-one Reactive Streams publisher with Reactor-style Mono operators. */
|
|
11
|
+
var Mono = class Mono extends Flux {
|
|
12
|
+
/** Creates a Mono from a lazy source factory. */
|
|
13
|
+
constructor(sourceFactory) {
|
|
14
|
+
super((signal, context) => {
|
|
15
|
+
const source = sourceFactory(signal, context);
|
|
16
|
+
if (!isAsyncIterable(source)) return (function* () {
|
|
17
|
+
if (signal.aborted) return;
|
|
18
|
+
const iterator = source[Symbol.iterator]();
|
|
19
|
+
try {
|
|
20
|
+
const first = iterator.next();
|
|
21
|
+
if (!first.done) yield first.value;
|
|
22
|
+
} finally {
|
|
23
|
+
iterator.return?.();
|
|
24
|
+
}
|
|
25
|
+
})();
|
|
26
|
+
return (async function* () {
|
|
27
|
+
const iterator = toAsyncIterator(source);
|
|
28
|
+
try {
|
|
29
|
+
const first = await raceWithAbort(iterator.next(), signal);
|
|
30
|
+
if (!first.done) yield first.value;
|
|
31
|
+
} finally {
|
|
32
|
+
await iterator.return?.();
|
|
33
|
+
}
|
|
34
|
+
})();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
/** Creates a Mono that emits exactly one non-nullish value. */
|
|
38
|
+
static just(value) {
|
|
39
|
+
throwIfNullish(value, "value");
|
|
40
|
+
return new Mono(function* () {
|
|
41
|
+
yield value;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/** Creates a Mono that completes without a value. */
|
|
45
|
+
static empty() {
|
|
46
|
+
return EMPTY_MONO;
|
|
47
|
+
}
|
|
48
|
+
/** Creates a Mono that never emits or completes until cancelled. */
|
|
49
|
+
static never() {
|
|
50
|
+
return NEVER_MONO;
|
|
51
|
+
}
|
|
52
|
+
/** Creates a Mono that terminates with the provided error. */
|
|
53
|
+
static error(error) {
|
|
54
|
+
return new Mono(async function* () {
|
|
55
|
+
throw typeof error === "function" ? error() : error;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/** Defers Mono source creation until subscription time. */
|
|
59
|
+
static defer(supplier) {
|
|
60
|
+
return new Mono((signal, context) => Flux.from(supplier()).next().iterate(signal, context));
|
|
61
|
+
}
|
|
62
|
+
/** Defers Mono source creation and exposes the subscriber context. */
|
|
63
|
+
static deferContextual(supplier) {
|
|
64
|
+
return new Mono((signal, context) => Flux.from(supplier(context.readOnly())).next().iterate(signal, context));
|
|
65
|
+
}
|
|
66
|
+
/** Relays the first Mono that emits any signal. */
|
|
67
|
+
static first(...sources) {
|
|
68
|
+
return Mono.firstWithSignal(...sources);
|
|
69
|
+
}
|
|
70
|
+
/** Adapts a source and keeps at most its first value. */
|
|
71
|
+
static from(input) {
|
|
72
|
+
if (input instanceof Mono) return input;
|
|
73
|
+
return Flux.from(input).next();
|
|
74
|
+
}
|
|
75
|
+
/** Creates a Mono from a promise-like value. */
|
|
76
|
+
static fromPromise(promise) {
|
|
77
|
+
return new Mono(async function* (signal) {
|
|
78
|
+
const value = await raceWithAbort(Promise.resolve(promise), signal);
|
|
79
|
+
if (value !== void 0 && value !== null) yield value;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/** Creates a Mono from a CompletionStage-like promise. */
|
|
83
|
+
static fromCompletionStage(stage) {
|
|
84
|
+
return typeof stage === "function" ? Mono.defer(() => Mono.fromPromise(stage())) : Mono.fromPromise(stage);
|
|
85
|
+
}
|
|
86
|
+
/** Creates a Mono from a Future-like promise. */
|
|
87
|
+
static fromFuture(future, _suppressCancel) {
|
|
88
|
+
return typeof future === "function" ? Mono.defer(() => Mono.fromPromise(future())) : Mono.fromPromise(future);
|
|
89
|
+
}
|
|
90
|
+
/** Adapts a publisher directly, preserving only its first value for Mono semantics. */
|
|
91
|
+
static fromDirect(input) {
|
|
92
|
+
return new Mono((signal, context) => Flux.from(input).iterate(signal, context));
|
|
93
|
+
}
|
|
94
|
+
/** Creates a Mono from a synchronous supplier. */
|
|
95
|
+
static fromSupplier(supplier) {
|
|
96
|
+
return new Mono(function* () {
|
|
97
|
+
const value = supplier();
|
|
98
|
+
if (value !== void 0 && value !== null) yield value;
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
/** Creates a Mono from a synchronous callable. */
|
|
102
|
+
static fromCallable(callable) {
|
|
103
|
+
return Mono.fromSupplier(callable);
|
|
104
|
+
}
|
|
105
|
+
/** Runs a callback and completes after it returns. */
|
|
106
|
+
static fromRunnable(runnable) {
|
|
107
|
+
return new Mono(function* () {
|
|
108
|
+
runnable();
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/** Creates a valued Mono for non-nullish input or an empty Mono otherwise. */
|
|
112
|
+
static justOrEmpty(value) {
|
|
113
|
+
return value === null || value === void 0 ? Mono.empty() : Mono.just(value);
|
|
114
|
+
}
|
|
115
|
+
/** Ignores every value from a source and completes when the source completes. */
|
|
116
|
+
static ignoreElements(source) {
|
|
117
|
+
return Flux.from(source).then();
|
|
118
|
+
}
|
|
119
|
+
/** Compares two sources element-by-element. */
|
|
120
|
+
static sequenceEqual(left, right, comparator = Object.is) {
|
|
121
|
+
return new Mono(async function* (signal, context) {
|
|
122
|
+
const leftIterator = toAsyncIterator(Flux.from(left).iterate(signal, context));
|
|
123
|
+
const rightIterator = toAsyncIterator(Flux.from(right).iterate(signal, context));
|
|
124
|
+
const nexts = new Array(2);
|
|
125
|
+
try {
|
|
126
|
+
for (;;) {
|
|
127
|
+
nexts[0] = raceWithAbort(leftIterator.next(), signal);
|
|
128
|
+
nexts[1] = raceWithAbort(rightIterator.next(), signal);
|
|
129
|
+
const [leftNext, rightNext] = await Promise.all(nexts);
|
|
130
|
+
if (leftNext.done || rightNext.done) {
|
|
131
|
+
yield Boolean(leftNext.done && rightNext.done);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
if (!comparator(leftNext.value, rightNext.value)) {
|
|
135
|
+
yield false;
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
} finally {
|
|
140
|
+
await closeAsyncIterator(leftIterator);
|
|
141
|
+
await closeAsyncIterator(rightIterator);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
/** Creates a Mono by bridging callback-style producers through a sink. */
|
|
146
|
+
static create(callback) {
|
|
147
|
+
throwIfNullish(callback, "callback");
|
|
148
|
+
return new Mono((signal) => {
|
|
149
|
+
const queue = new AsyncQueue(signal);
|
|
150
|
+
let cancelled = false;
|
|
151
|
+
let terminated = false;
|
|
152
|
+
let cancelCallbacks;
|
|
153
|
+
const sink = {
|
|
154
|
+
/** Emits one value and completes this Mono sink. */
|
|
155
|
+
next(value) {
|
|
156
|
+
this.success(value);
|
|
157
|
+
},
|
|
158
|
+
/** Completes this Mono sink without a value. */
|
|
159
|
+
complete() {
|
|
160
|
+
this.success();
|
|
161
|
+
},
|
|
162
|
+
/** Completes this Mono sink with an optional value. */
|
|
163
|
+
success(value) {
|
|
164
|
+
if (terminated) return;
|
|
165
|
+
terminated = true;
|
|
166
|
+
if (value !== void 0 && value !== null) queue.push(value);
|
|
167
|
+
queue.complete();
|
|
168
|
+
},
|
|
169
|
+
/** Terminates this Mono sink with an error. */
|
|
170
|
+
error(error) {
|
|
171
|
+
if (terminated) return;
|
|
172
|
+
terminated = true;
|
|
173
|
+
queue.error(error);
|
|
174
|
+
},
|
|
175
|
+
/** Registers a callback invoked when the subscription is cancelled. */
|
|
176
|
+
onCancel(cancelCallback) {
|
|
177
|
+
cancelCallbacks = addCancelCallback(cancelCallbacks, cancelCallback);
|
|
178
|
+
return sink;
|
|
179
|
+
},
|
|
180
|
+
/** Returns true after cancellation has been observed. */
|
|
181
|
+
isCancelled() {
|
|
182
|
+
return cancelled || signal.aborted;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
signal.addEventListener("abort", () => {
|
|
186
|
+
cancelled = true;
|
|
187
|
+
runCancelCallbacks(cancelCallbacks);
|
|
188
|
+
cancelCallbacks = void 0;
|
|
189
|
+
queue.complete();
|
|
190
|
+
}, { once: true });
|
|
191
|
+
try {
|
|
192
|
+
callback(sink);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
queue.error(error);
|
|
195
|
+
}
|
|
196
|
+
return queue;
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/** Emits `0` after the provided delay. */
|
|
200
|
+
static delay(duration, scheduler = Schedulers.timeout()) {
|
|
201
|
+
return new Mono(async function* (signal) {
|
|
202
|
+
await scheduleDelay(scheduler, duration, signal);
|
|
203
|
+
yield 0;
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
/** Completes when all provided publishers complete. */
|
|
207
|
+
static when(...sources) {
|
|
208
|
+
if (sources.length === 0) return Mono.empty();
|
|
209
|
+
if (sources.length === 1) return new Mono(async function* (signal, context) {
|
|
210
|
+
await drainPublisherInput(sources[0], signal, context);
|
|
211
|
+
});
|
|
212
|
+
return new Mono(async function* (signal, context) {
|
|
213
|
+
await Promise.all(completionTasks(sources, signal, context));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/** Completes when all provided publishers complete and delays failures until all terminate. */
|
|
217
|
+
static whenDelayError(...sources) {
|
|
218
|
+
if (sources.length === 0) return Mono.empty();
|
|
219
|
+
if (sources.length === 1) return new Mono(async function* (signal, context) {
|
|
220
|
+
await drainPublisherInputAsCompositeError(sources[0], signal, context);
|
|
221
|
+
});
|
|
222
|
+
return new Mono(async function* (signal, context) {
|
|
223
|
+
const errors = [];
|
|
224
|
+
await Promise.all(completionDelayErrorTasks(sources, signal, context, errors));
|
|
225
|
+
if (errors.length > 0) throw new CompositeError(errors);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
/** Relays the first source to signal value, completion or error. */
|
|
229
|
+
static firstWithSignal(...sources) {
|
|
230
|
+
if (sources.length === 0) return Mono.empty();
|
|
231
|
+
if (sources.length === 1) return Mono.from(sources[0]);
|
|
232
|
+
return new Mono((signal) => {
|
|
233
|
+
const queue = new AsyncQueue(signal);
|
|
234
|
+
let settled = false;
|
|
235
|
+
for (const source of sources) (async () => {
|
|
236
|
+
try {
|
|
237
|
+
const value = await firstValueFrom(Flux.from(source), signal);
|
|
238
|
+
if (!settled) {
|
|
239
|
+
settled = true;
|
|
240
|
+
if (value !== void 0) queue.push(value);
|
|
241
|
+
queue.complete();
|
|
242
|
+
}
|
|
243
|
+
} catch (error) {
|
|
244
|
+
if (!settled) {
|
|
245
|
+
settled = true;
|
|
246
|
+
queue.error(error);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
})();
|
|
250
|
+
return queue;
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
/** Relays the first non-empty value from the provided sources. */
|
|
254
|
+
static firstWithValue(...sources) {
|
|
255
|
+
if (sources.length === 0) return Mono.empty();
|
|
256
|
+
if (sources.length === 1) return Mono.from(sources[0]);
|
|
257
|
+
return new Mono((signal) => {
|
|
258
|
+
const queue = new AsyncQueue(signal);
|
|
259
|
+
let remaining = sources.length;
|
|
260
|
+
const errors = [];
|
|
261
|
+
for (const source of sources) (async () => {
|
|
262
|
+
try {
|
|
263
|
+
const value = await firstValueFrom(Flux.from(source), signal);
|
|
264
|
+
if (value !== void 0) {
|
|
265
|
+
queue.push(value);
|
|
266
|
+
queue.complete();
|
|
267
|
+
} else {
|
|
268
|
+
remaining -= 1;
|
|
269
|
+
if (remaining === 0) errors.length > 0 ? queue.error(new CompositeError(errors)) : queue.complete();
|
|
270
|
+
}
|
|
271
|
+
} catch (error) {
|
|
272
|
+
errors.push(error);
|
|
273
|
+
remaining -= 1;
|
|
274
|
+
if (remaining === 0) queue.error(new CompositeError(errors));
|
|
275
|
+
}
|
|
276
|
+
})();
|
|
277
|
+
return queue;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
/** Zips Monos by combining one value from each source. */
|
|
281
|
+
static zip(sources, combinator) {
|
|
282
|
+
return Flux.zip(sources, combinator).next();
|
|
283
|
+
}
|
|
284
|
+
/** Zips Monos by combining one value from each source while delaying source failures. */
|
|
285
|
+
static zipDelayError(sources, combinator) {
|
|
286
|
+
const sourceCount = sources.length;
|
|
287
|
+
if (sourceCount === 0) return Mono.empty();
|
|
288
|
+
if (sourceCount === 1) return singleZipDelayError(sources[0], combinator);
|
|
289
|
+
return new Mono(async function* (signal, context) {
|
|
290
|
+
const values = new Array(sourceCount);
|
|
291
|
+
const errors = [];
|
|
292
|
+
const tasks = new Array(sourceCount);
|
|
293
|
+
for (let index = 0; index < sourceCount; index += 1) tasks[index] = (async () => {
|
|
294
|
+
try {
|
|
295
|
+
values[index] = await firstValueFrom(Flux.from(sources[index]), signal);
|
|
296
|
+
} catch (error) {
|
|
297
|
+
errors.push(error);
|
|
298
|
+
}
|
|
299
|
+
})();
|
|
300
|
+
await Promise.all(tasks);
|
|
301
|
+
if (errors.length > 0) throw new CompositeError(errors);
|
|
302
|
+
for (let index = 0; index < sourceCount; index += 1) if (values[index] === void 0) return;
|
|
303
|
+
const tuple = values;
|
|
304
|
+
yield combinator ? combinator(tuple) : tuple;
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
/** Uses a resource for the duration of a derived Mono and cleans it up afterwards. */
|
|
308
|
+
static using(resourceSupplier, sourceFactory, resourceCleanup) {
|
|
309
|
+
return Flux.using(resourceSupplier, sourceFactory, resourceCleanup).next();
|
|
310
|
+
}
|
|
311
|
+
/** Uses an asynchronously supplied resource and runs asynchronous cleanup publishers. */
|
|
312
|
+
static usingWhen(resourceSupplier, sourceFactory, asyncComplete, asyncError, asyncCancel) {
|
|
313
|
+
return Flux.usingWhen(resourceSupplier, sourceFactory, asyncComplete, asyncError, asyncCancel).next();
|
|
314
|
+
}
|
|
315
|
+
/** Resolves to the Mono value, or undefined when empty. */
|
|
316
|
+
async block() {
|
|
317
|
+
return this.toPromise();
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
/** Shared stateless empty Mono instance. */
|
|
321
|
+
var EMPTY_MONO = new Mono(() => EMPTY_ITERABLE);
|
|
322
|
+
/** Shared stateless never Mono instance. */
|
|
323
|
+
var NEVER_MONO = new Mono((signal) => neverIterable(signal));
|
|
324
|
+
/** Zips one source without allocating multi-source coordination state. */
|
|
325
|
+
function singleZipDelayError(source, combinator) {
|
|
326
|
+
return new Mono(async function* (signal) {
|
|
327
|
+
let value;
|
|
328
|
+
try {
|
|
329
|
+
value = await firstValueFrom(Flux.from(source), signal);
|
|
330
|
+
} catch (error) {
|
|
331
|
+
throw new CompositeError([error]);
|
|
332
|
+
}
|
|
333
|
+
if (value === void 0) return;
|
|
334
|
+
const tuple = [value];
|
|
335
|
+
yield combinator ? combinator(tuple) : tuple;
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/** Creates completion tasks for publishers whose values are ignored. */
|
|
339
|
+
function completionTasks(sources, signal, context) {
|
|
340
|
+
const tasks = new Array(sources.length);
|
|
341
|
+
for (let index = 0; index < sources.length; index += 1) tasks[index] = drainPublisherInput(sources[index], signal, context);
|
|
342
|
+
return tasks;
|
|
343
|
+
}
|
|
344
|
+
/** Creates completion tasks that collect failures until every publisher has terminated. */
|
|
345
|
+
function completionDelayErrorTasks(sources, signal, context, errors) {
|
|
346
|
+
const tasks = new Array(sources.length);
|
|
347
|
+
for (let index = 0; index < sources.length; index += 1) tasks[index] = drainPublisherInputDelayError(sources[index], signal, context, errors);
|
|
348
|
+
return tasks;
|
|
349
|
+
}
|
|
350
|
+
/** Consumes a publisher and ignores every value. */
|
|
351
|
+
async function drainPublisherInput(source, signal, context) {
|
|
352
|
+
for await (const _ of Flux.from(source).iterate(signal, context));
|
|
353
|
+
}
|
|
354
|
+
/** Consumes one publisher and wraps its failure like delayed-error composition. */
|
|
355
|
+
async function drainPublisherInputAsCompositeError(source, signal, context) {
|
|
356
|
+
try {
|
|
357
|
+
await drainPublisherInput(source, signal, context);
|
|
358
|
+
} catch (error) {
|
|
359
|
+
throw new CompositeError([error]);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
/** Consumes a publisher and records its failure instead of throwing immediately. */
|
|
363
|
+
async function drainPublisherInputDelayError(source, signal, context, errors) {
|
|
364
|
+
try {
|
|
365
|
+
await drainPublisherInput(source, signal, context);
|
|
366
|
+
} catch (error) {
|
|
367
|
+
errors.push(error);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
//#endregion
|
|
371
|
+
export { Mono };
|
|
372
|
+
|
|
373
|
+
//# sourceMappingURL=mono.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mono.js","names":[],"sources":["../../src/publisher/mono.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport type {Context} from \"@/context/context.js\";\nimport type {ContextView} from \"@/context/context-view.js\";\nimport {CompositeError} from \"@/errors/classes.js\";\nimport {throwIfNullish} from \"@/errors/helpers.js\";\nimport {firstValueFrom, raceWithAbort} from \"@/internal/abort.js\";\nimport {AsyncQueue} from \"@/internal/async-queue.js\";\nimport {closeAsyncIterator, EMPTY_ITERABLE, isAsyncIterable, neverIterable, toAsyncIterator} from \"@/internal/iterable.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {addCancelCallback, type CancelCallbacks, runCancelCallbacks, scheduleDelay} from \"@/publisher/helpers.js\";\nimport type {MonoSinkCallback, PublisherInput, SourceFactory} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\n\n/** Zero-or-one Reactive Streams publisher with Reactor-style Mono operators. */\nexport class Mono<T> extends Flux<T> {\n /** Creates a Mono from a lazy source factory. */\n public constructor(sourceFactory: SourceFactory<T>) {\n super((signal, context) => {\n const source = sourceFactory(signal, context);\n if (!isAsyncIterable<T>(source)) {\n return (function* () {\n if (signal.aborted) {\n return;\n }\n const iterator = source[Symbol.iterator]();\n try {\n const first = iterator.next();\n if (!first.done) {\n yield first.value;\n }\n } finally {\n iterator.return?.();\n }\n })();\n }\n return (async function* () {\n const iterator = toAsyncIterator(source);\n try {\n const first = await raceWithAbort(iterator.next(), signal);\n if (!first.done) {\n yield first.value;\n }\n } finally {\n await iterator.return?.();\n }\n })();\n });\n }\n\n /** Creates a Mono that emits exactly one non-nullish value. */\n public static override just<T>(value: T): Mono<T> {\n throwIfNullish(value, \"value\");\n return new Mono(function* () {\n yield value;\n });\n }\n\n /** Creates a Mono that completes without a value. */\n public static override empty<T = never>(): Mono<T> {\n return EMPTY_MONO as Mono<T>;\n }\n\n /** Creates a Mono that never emits or completes until cancelled. */\n public static override never<T = never>(): Mono<T> {\n return NEVER_MONO as Mono<T>;\n }\n\n /** Creates a Mono that terminates with the provided error. */\n public static override error<T = never>(error: unknown | (() => unknown)): Mono<T> {\n return new Mono(async function* () {\n throw typeof error === \"function\" ? (error as () => unknown)() : error;\n });\n }\n\n /** Defers Mono source creation until subscription time. */\n public static override defer<T>(supplier: () => PublisherInput<T>): Mono<T> {\n return new Mono((signal, context) => Flux.from(supplier()).next().iterate(signal, context));\n }\n\n /** Defers Mono source creation and exposes the subscriber context. */\n public static override deferContextual<T>(supplier: (context: ContextView) => PublisherInput<T>): Mono<T> {\n return new Mono((signal, context) => Flux.from(supplier(context.readOnly())).next().iterate(signal, context));\n }\n\n /** Relays the first Mono that emits any signal. */\n public static override first<T>(...sources: readonly PublisherInput<T>[]): Mono<T> {\n return Mono.firstWithSignal(...sources);\n }\n\n /** Adapts a source and keeps at most its first value. */\n public static override from<T>(input: PublisherInput<T>): Mono<T> {\n if (input instanceof Mono) {\n return input;\n }\n return Flux.from(input).next();\n }\n\n /** Creates a Mono from a promise-like value. */\n public static fromPromise<T>(promise: PromiseLike<T>): Mono<T> {\n return new Mono(async function* (signal) {\n const value = await raceWithAbort(Promise.resolve(promise), signal);\n if (value !== undefined && value !== null) {\n yield value;\n }\n });\n }\n\n /** Creates a Mono from a CompletionStage-like promise. */\n public static fromCompletionStage<T>(stage: PromiseLike<T> | (() => PromiseLike<T>)): Mono<T> {\n return typeof stage === \"function\" ? Mono.defer(() => Mono.fromPromise((stage as () => PromiseLike<T>)())) : Mono.fromPromise(stage);\n }\n\n /** Creates a Mono from a Future-like promise. */\n public static fromFuture<T>(future: PromiseLike<T> | (() => PromiseLike<T>), _suppressCancel?: boolean): Mono<T> {\n return typeof future === \"function\" ? Mono.defer(() => Mono.fromPromise((future as () => PromiseLike<T>)())) : Mono.fromPromise(future);\n }\n\n /** Adapts a publisher directly, preserving only its first value for Mono semantics. */\n public static fromDirect<T>(input: PublisherInput<T>): Mono<T> {\n return new Mono((signal, context) => Flux.from(input).iterate(signal, context));\n }\n\n /** Creates a Mono from a synchronous supplier. */\n public static fromSupplier<T>(supplier: () => T | null | undefined): Mono<T> {\n return new Mono(function* () {\n const value = supplier();\n if (value !== undefined && value !== null) {\n yield value;\n }\n });\n }\n\n /** Creates a Mono from a synchronous callable. */\n public static fromCallable<T>(callable: () => T | null | undefined): Mono<T> {\n return Mono.fromSupplier(callable);\n }\n\n /** Runs a callback and completes after it returns. */\n public static fromRunnable(runnable: () => void): Mono<void> {\n return new Mono(function* () {\n runnable();\n });\n }\n\n /** Creates a valued Mono for non-nullish input or an empty Mono otherwise. */\n public static justOrEmpty<T>(value: T | null | undefined): Mono<T> {\n return value === null || value === undefined ? Mono.empty<T>() : Mono.just(value);\n }\n\n /** Ignores every value from a source and completes when the source completes. */\n public static ignoreElements<T>(source: PublisherInput<T>): Mono<T> {\n return Flux.from(source).then() as unknown as Mono<T>;\n }\n\n /** Compares two sources element-by-element. */\n public static sequenceEqual<T>(\n left: PublisherInput<T>,\n right: PublisherInput<T>,\n comparator: (left: T, right: T) => boolean = Object.is\n ): Mono<boolean> {\n return new Mono(async function* (signal, context) {\n const leftIterator = toAsyncIterator(Flux.from(left).iterate(signal, context));\n const rightIterator = toAsyncIterator(Flux.from(right).iterate(signal, context));\n const nexts: [\n Promise<IteratorResult<T>>,\n Promise<IteratorResult<T>>\n ] = new Array<Promise<IteratorResult<T>>>(2) as [\n Promise<IteratorResult<T>>,\n Promise<IteratorResult<T>>\n ];\n try {\n for (; ;) {\n nexts[0] = raceWithAbort(leftIterator.next(), signal);\n nexts[1] = raceWithAbort(rightIterator.next(), signal);\n const [leftNext, rightNext] = await Promise.all(nexts);\n if (leftNext.done || rightNext.done) {\n yield Boolean(leftNext.done && rightNext.done);\n return;\n }\n if (!comparator(leftNext.value, rightNext.value)) {\n yield false;\n return;\n }\n }\n } finally {\n await closeAsyncIterator(leftIterator);\n await closeAsyncIterator(rightIterator);\n }\n });\n }\n\n /** Creates a Mono by bridging callback-style producers through a sink. */\n public static override create<T>(callback: MonoSinkCallback<T>): Mono<T> {\n throwIfNullish(callback, \"callback\");\n return new Mono(signal => {\n const queue = new AsyncQueue<T>(signal);\n let cancelled = false;\n let terminated = false;\n let cancelCallbacks: CancelCallbacks | undefined;\n const sink = {\n /** Emits one value and completes this Mono sink. */\n next(value: T) {\n this.success(value);\n },\n /** Completes this Mono sink without a value. */\n complete() {\n this.success();\n },\n /** Completes this Mono sink with an optional value. */\n success(value?: T) {\n if (terminated) {\n return;\n }\n terminated = true;\n if (value !== undefined && value !== null) {\n queue.push(value);\n }\n queue.complete();\n },\n /** Terminates this Mono sink with an error. */\n error(error: unknown) {\n if (terminated) {\n return;\n }\n terminated = true;\n queue.error(error);\n },\n /** Registers a callback invoked when the subscription is cancelled. */\n onCancel(cancelCallback: () => void) {\n cancelCallbacks = addCancelCallback(cancelCallbacks, cancelCallback);\n return sink;\n },\n /** Returns true after cancellation has been observed. */\n isCancelled() {\n return cancelled || signal.aborted;\n }\n };\n signal.addEventListener(\n \"abort\",\n () => {\n cancelled = true;\n runCancelCallbacks(cancelCallbacks);\n cancelCallbacks = undefined;\n queue.complete();\n },\n {once: true}\n );\n try {\n callback(sink);\n } catch (error) {\n queue.error(error);\n }\n return queue;\n });\n }\n\n /** Emits `0` after the provided delay. */\n public static delay(duration: DurationInput, scheduler: Scheduler = Schedulers.timeout()): Mono<number> {\n return new Mono(async function* (signal) {\n await scheduleDelay(scheduler, duration, signal);\n yield 0;\n });\n }\n\n /** Completes when all provided publishers complete. */\n public static when(...sources: readonly PublisherInput<unknown>[]): Mono<void> {\n if (sources.length === 0) {\n return Mono.empty<void>();\n }\n if (sources.length === 1) {\n return new Mono(async function* (signal, context) {\n await drainPublisherInput(sources[0]!, signal, context);\n });\n }\n return new Mono(async function* (signal, context) {\n await Promise.all(completionTasks(sources, signal, context));\n });\n }\n\n /** Completes when all provided publishers complete and delays failures until all terminate. */\n public static whenDelayError(...sources: readonly PublisherInput<unknown>[]): Mono<void> {\n if (sources.length === 0) {\n return Mono.empty<void>();\n }\n if (sources.length === 1) {\n return new Mono(async function* (signal, context) {\n await drainPublisherInputAsCompositeError(sources[0]!, signal, context);\n });\n }\n return new Mono(async function* (signal, context) {\n const errors: unknown[] = [];\n await Promise.all(completionDelayErrorTasks(sources, signal, context, errors));\n if (errors.length > 0) {\n throw new CompositeError(errors);\n }\n });\n }\n\n /** Relays the first source to signal value, completion or error. */\n public static override firstWithSignal<T>(...sources: readonly PublisherInput<T>[]): Mono<T> {\n if (sources.length === 0) {\n return Mono.empty<T>();\n }\n if (sources.length === 1) {\n return Mono.from(sources[0]!);\n }\n return new Mono(signal => {\n const queue = new AsyncQueue<T>(signal);\n let settled = false;\n for (const source of sources) {\n void (async () => {\n try {\n const value = await firstValueFrom(Flux.from(source), signal);\n if (!settled) {\n settled = true;\n if (value !== undefined) {\n queue.push(value);\n }\n queue.complete();\n }\n } catch (error) {\n if (!settled) {\n settled = true;\n queue.error(error);\n }\n }\n })();\n }\n return queue;\n });\n }\n\n /** Relays the first non-empty value from the provided sources. */\n public static override firstWithValue<T>(...sources: readonly PublisherInput<T>[]): Mono<T> {\n if (sources.length === 0) {\n return Mono.empty<T>();\n }\n if (sources.length === 1) {\n return Mono.from(sources[0]!);\n }\n return new Mono(signal => {\n const queue = new AsyncQueue<T>(signal);\n let remaining = sources.length;\n const errors: unknown[] = [];\n for (const source of sources) {\n void (async () => {\n try {\n const value = await firstValueFrom(Flux.from(source), signal);\n if (value !== undefined) {\n queue.push(value);\n queue.complete();\n } else {\n remaining -= 1;\n if (remaining === 0) {\n errors.length > 0 ? queue.error(new CompositeError(errors)) : queue.complete();\n }\n }\n } catch (error) {\n errors.push(error);\n remaining -= 1;\n if (remaining === 0) {\n queue.error(new CompositeError(errors));\n }\n }\n })();\n }\n return queue;\n });\n }\n\n /** Zips Monos by combining one value from each source. */\n public static override zip<T extends readonly unknown[], R = T>(\n sources: { [K in keyof T]: PublisherInput<T[K]> },\n combinator?: (values: T) => R\n ): Mono<R> {\n return Flux.zip(sources, combinator).next();\n }\n\n /** Zips Monos by combining one value from each source while delaying source failures. */\n public static zipDelayError<T extends readonly unknown[], R = T>(\n sources: { [K in keyof T]: PublisherInput<T[K]> },\n combinator?: (values: T) => R\n ): Mono<R> {\n const sourceCount = sources.length;\n if (sourceCount === 0) {\n return Mono.empty<R>();\n }\n if (sourceCount === 1) {\n return singleZipDelayError(sources[0]!, combinator);\n }\n return new Mono(async function* (signal, context) {\n const values = new Array<unknown>(sourceCount);\n const errors: unknown[] = [];\n const tasks = new Array<Promise<void>>(sourceCount);\n for (let index = 0; index < sourceCount; index += 1) {\n tasks[index] = (async () => {\n try {\n values[index] = await firstValueFrom(Flux.from(sources[index]!), signal);\n } catch (error) {\n errors.push(error);\n }\n })();\n }\n await Promise.all(tasks);\n if (errors.length > 0) {\n throw new CompositeError(errors);\n }\n for (let index = 0; index < sourceCount; index += 1) {\n if (values[index] === undefined) {\n return;\n }\n }\n const tuple = values as unknown as T;\n yield combinator ? combinator(tuple) : (tuple as unknown as R);\n });\n }\n\n /** Uses a resource for the duration of a derived Mono and cleans it up afterwards. */\n public static override using<T, D>(\n resourceSupplier: () => D,\n sourceFactory: (resource: D) => PublisherInput<T>,\n resourceCleanup?: (resource: D) => void\n ): Mono<T> {\n return Flux.using(resourceSupplier, sourceFactory, resourceCleanup).next();\n }\n\n /** Uses an asynchronously supplied resource and runs asynchronous cleanup publishers. */\n public static override usingWhen<T, D>(\n resourceSupplier: PublisherInput<D>,\n sourceFactory: (resource: D) => PublisherInput<T>,\n asyncComplete?: (resource: D) => PublisherInput<unknown>,\n asyncError?: (resource: D, error: unknown) => PublisherInput<unknown>,\n asyncCancel?: (resource: D) => PublisherInput<unknown>\n ): Mono<T> {\n return Flux.usingWhen(resourceSupplier, sourceFactory, asyncComplete, asyncError, asyncCancel).next();\n }\n\n /** Resolves to the Mono value, or undefined when empty. */\n public async block(): Promise<T | undefined> {\n return this.toPromise();\n }\n}\n\n/** Shared stateless empty Mono instance. */\nconst EMPTY_MONO = new Mono<never>(() => EMPTY_ITERABLE);\n\n/** Shared stateless never Mono instance. */\nconst NEVER_MONO = new Mono<never>(signal => neverIterable(signal));\n\n/** Zips one source without allocating multi-source coordination state. */\nfunction singleZipDelayError<T extends readonly unknown[], R>(\n source: PublisherInput<T[0]>,\n combinator: ((values: T) => R) | undefined\n): Mono<R> {\n return new Mono(async function* (signal) {\n let value: T[0] | undefined;\n try {\n value = await firstValueFrom(Flux.from(source), signal);\n } catch (error) {\n throw new CompositeError([error]);\n }\n if (value === undefined) {\n return;\n }\n const tuple = [value] as unknown as T;\n yield combinator ? combinator(tuple) : (tuple as unknown as R);\n });\n}\n\n/** Creates completion tasks for publishers whose values are ignored. */\nfunction completionTasks(\n sources: readonly PublisherInput<unknown>[],\n signal: AbortSignal,\n context: Context\n): Promise<void>[] {\n const tasks = new Array<Promise<void>>(sources.length);\n for (let index = 0; index < sources.length; index += 1) {\n tasks[index] = drainPublisherInput(sources[index]!, signal, context);\n }\n return tasks;\n}\n\n/** Creates completion tasks that collect failures until every publisher has terminated. */\nfunction completionDelayErrorTasks(\n sources: readonly PublisherInput<unknown>[],\n signal: AbortSignal,\n context: Context,\n errors: unknown[]\n): Promise<void>[] {\n const tasks = new Array<Promise<void>>(sources.length);\n for (let index = 0; index < sources.length; index += 1) {\n tasks[index] = drainPublisherInputDelayError(sources[index]!, signal, context, errors);\n }\n return tasks;\n}\n\n/** Consumes a publisher and ignores every value. */\nasync function drainPublisherInput(source: PublisherInput<unknown>, signal: AbortSignal, context: Context): Promise<void> {\n for await (const _ of Flux.from(source).iterate(signal, context)) {\n // values are intentionally ignored\n }\n}\n\n/** Consumes one publisher and wraps its failure like delayed-error composition. */\nasync function drainPublisherInputAsCompositeError(\n source: PublisherInput<unknown>,\n signal: AbortSignal,\n context: Context\n): Promise<void> {\n try {\n await drainPublisherInput(source, signal, context);\n } catch (error) {\n throw new CompositeError([error]);\n }\n}\n\n/** Consumes a publisher and records its failure instead of throwing immediately. */\nasync function drainPublisherInputDelayError(\n source: PublisherInput<unknown>,\n signal: AbortSignal,\n context: Context,\n errors: unknown[]\n): Promise<void> {\n try {\n await drainPublisherInput(source, signal, context);\n } catch (error) {\n errors.push(error);\n }\n}\n"],"mappings":";;;;;;;;;;AAkBA,IAAa,OAAb,MAAa,aAAgB,KAAQ;;CAEjC,YAAmB,eAAiC;EAChD,OAAO,QAAQ,YAAY;GACvB,MAAM,SAAS,cAAc,QAAQ,OAAO;GAC5C,IAAI,CAAC,gBAAmB,MAAM,GAC1B,QAAQ,aAAa;IACjB,IAAI,OAAO,SACP;IAEJ,MAAM,WAAW,OAAO,OAAO,SAAS,CAAC;IACzC,IAAI;KACA,MAAM,QAAQ,SAAS,KAAK;KAC5B,IAAI,CAAC,MAAM,MACP,MAAM,MAAM;IAEpB,UAAU;KACN,SAAS,SAAS;IACtB;GACJ,EAAA,CAAG;GAEP,QAAQ,mBAAmB;IACvB,MAAM,WAAW,gBAAgB,MAAM;IACvC,IAAI;KACA,MAAM,QAAQ,MAAM,cAAc,SAAS,KAAK,GAAG,MAAM;KACzD,IAAI,CAAC,MAAM,MACP,MAAM,MAAM;IAEpB,UAAU;KACN,MAAM,SAAS,SAAS;IAC5B;GACJ,EAAA,CAAG;EACP,CAAC;CACL;;CAGA,OAAuB,KAAQ,OAAmB;EAC9C,eAAe,OAAO,OAAO;EAC7B,OAAO,IAAI,KAAK,aAAa;GACzB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EvE,OAAO;AACX;;AAGA,SAAS,0BACL,SACA,QACA,SACA,QACe;CACf,MAAM,QAAQ,IAAI,MAAqB,QAAQ,MAAM;CACrD,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,SAAS,GACjD,MAAM,SAAS,8BAA8B,QAAQ,QAAS,QAAQ,SAAS,MAAM;CAEzF,OAAO;AACX;;AAGA,eAAe,oBAAoB,QAAiC,QAAqB,SAAiC;CACtH,WAAW,MAAM,KAAK,KAAK,KAAK,MAAM,CAAC,CAAC,QAAQ,QAAQ,OAAO;AAGnE;;AAGA,eAAe,oCACX,QACA,QACA,SACa;CACb,IAAI;EACA,MAAM,oBAAoB,QAAQ,QAAQ,OAAO;CACrD,SAAS,OAAO;EACZ,MAAM,IAAI,eAAe,CAAC,KAAK,CAAC;CACpC;AACJ;;AAGA,eAAe,8BACX,QACA,QACA,SACA,QACa;CACb,IAAI;EACA,MAAM,oBAAoB,QAAQ,QAAQ,OAAO;CACrD,SAAS,OAAO;EACZ,OAAO,KAAK,KAAK;CACrB;AACJ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Mono } from "../mono.js";
|
|
2
|
+
declare module "../flux.js" {
|
|
3
|
+
/** Aggregate and terminal count-style operators added to Flux. */
|
|
4
|
+
interface Flux<T> {
|
|
5
|
+
/** Groups source values into arrays of `size`, with a final partial buffer when needed. */
|
|
6
|
+
buffer(size: number): Flux<T[]>;
|
|
7
|
+
/** Splits source values into finite Flux windows containing up to `size` values each. */
|
|
8
|
+
window(size: number): Flux<Flux<T>>;
|
|
9
|
+
/** Emits the seed and each accumulated value produced from the source. */
|
|
10
|
+
scan<R>(seed: R, accumulator: (accumulated: R, value: T) => R): Flux<R>;
|
|
11
|
+
/** Emits running accumulated values, using the first source value as the initial state. */
|
|
12
|
+
scan(accumulator: (accumulated: T, value: T) => T): Flux<T>;
|
|
13
|
+
/** Reduces source values into one value, using the first value as the initial state. */
|
|
14
|
+
reduce(accumulator: (left: T, right: T) => T): Mono<T>;
|
|
15
|
+
/** Reduces source values into one value starting from the provided seed. */
|
|
16
|
+
reduce<R>(seed: R, accumulator: (left: R, right: T) => R): Mono<R>;
|
|
17
|
+
/** Collects all source values into an array emitted after completion. */
|
|
18
|
+
collectList(): Mono<T[]>;
|
|
19
|
+
/** Counts source values and emits the final count after completion. */
|
|
20
|
+
count(): Mono<number>;
|
|
21
|
+
/** Emits true when at least one source value matches the predicate. */
|
|
22
|
+
any(predicate: (value: T) => boolean): Mono<boolean>;
|
|
23
|
+
/** Emits true only when every source value matches the predicate. */
|
|
24
|
+
all(predicate: (value: T) => boolean): Mono<boolean>;
|
|
25
|
+
/** Emits true when a source value matches `value` by `Object.is`. */
|
|
26
|
+
hasElement(value: T): Mono<boolean>;
|
|
27
|
+
/** Emits the first source value, or completes empty when the source has none. */
|
|
28
|
+
next(): Mono<T>;
|
|
29
|
+
/** Emits the only source value, an optional default for empty sources, or fails on multiple values. */
|
|
30
|
+
single(defaultValue?: T): Mono<T>;
|
|
31
|
+
/** Emits the only source value, completes empty for empty sources, or fails on multiple values. */
|
|
32
|
+
singleOrEmpty(): Mono<T>;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=aggregate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../../../src/publisher/operators/aggregate.ts"],"names":[],"mappings":"AASA,OAAO,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAQzC,OAAO,QAAQ,qBAAqB,CAAC;IACjC,kEAAkE;IAClE,UAAU,IAAI,CAAC,CAAC;QACZ,2FAA2F;QAC3F,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC;QAEhC,yFAAyF;QACzF,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAEpC,0EAA0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