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,144 @@
|
|
|
1
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
|
+
import { AsyncQueue } from "../internal/async-queue.js";
|
|
3
|
+
import { SignalType } from "../signal/signal-type.js";
|
|
4
|
+
import { Mono } from "../publisher/mono.js";
|
|
5
|
+
import { addSinkSubscriber, clearSinkSubscribers, removeSinkSubscriber, sinkSubscriberCount } from "./subscribers.js";
|
|
6
|
+
import { EmitFailureHandlers, EmitResult, emitOrThrow } from "./types.js";
|
|
7
|
+
//#region src/sinks/one.ts
|
|
8
|
+
/**
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
* Sink specifications and default browser-oriented sink implementations.
|
|
11
|
+
*/
|
|
12
|
+
/** Default replaying implementation for `Sinks.one()` and `Sinks.empty()`. */
|
|
13
|
+
var DefaultOneSink = class {
|
|
14
|
+
constructor() {
|
|
15
|
+
_defineProperty(
|
|
16
|
+
this,
|
|
17
|
+
/** Current terminal or pending state of the sink. */
|
|
18
|
+
"state",
|
|
19
|
+
"pending"
|
|
20
|
+
);
|
|
21
|
+
_defineProperty(
|
|
22
|
+
this,
|
|
23
|
+
/** Stored value replayed to late subscribers after successful termination. */
|
|
24
|
+
"value",
|
|
25
|
+
void 0
|
|
26
|
+
);
|
|
27
|
+
_defineProperty(
|
|
28
|
+
this,
|
|
29
|
+
/** Stored error replayed to late subscribers after failed termination. */
|
|
30
|
+
"errorValue",
|
|
31
|
+
void 0
|
|
32
|
+
);
|
|
33
|
+
_defineProperty(
|
|
34
|
+
this,
|
|
35
|
+
/** Active subscriber queues waiting for the terminal result, created only when needed. */
|
|
36
|
+
"subscribers",
|
|
37
|
+
void 0
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
/** Returns the Mono view of this sink. */
|
|
41
|
+
asMono() {
|
|
42
|
+
return new Mono((signal) => {
|
|
43
|
+
const queue = new AsyncQueue(signal);
|
|
44
|
+
this.replay(queue);
|
|
45
|
+
if (this.state === "pending") this.addSubscriber(queue, signal);
|
|
46
|
+
return queue;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/** Attempts to emit a value and complete this sink. */
|
|
50
|
+
tryEmitValue(value) {
|
|
51
|
+
if (this.state !== "pending") return EmitResult.FAIL_TERMINATED;
|
|
52
|
+
this.state = "value";
|
|
53
|
+
this.value = value;
|
|
54
|
+
const subscribers = this.subscribers;
|
|
55
|
+
if (subscribers instanceof Set) for (const subscriber of subscribers) {
|
|
56
|
+
subscriber.push(value);
|
|
57
|
+
subscriber.complete();
|
|
58
|
+
}
|
|
59
|
+
else if (subscribers) {
|
|
60
|
+
subscribers.push(value);
|
|
61
|
+
subscribers.complete();
|
|
62
|
+
}
|
|
63
|
+
this.clearSubscribers();
|
|
64
|
+
return EmitResult.OK;
|
|
65
|
+
}
|
|
66
|
+
/** Attempts to complete this sink without a value. */
|
|
67
|
+
tryEmitEmpty() {
|
|
68
|
+
if (this.state !== "pending") return EmitResult.FAIL_TERMINATED;
|
|
69
|
+
this.state = "empty";
|
|
70
|
+
const subscribers = this.subscribers;
|
|
71
|
+
if (subscribers instanceof Set) for (const subscriber of subscribers) subscriber.complete();
|
|
72
|
+
else if (subscribers) subscribers.complete();
|
|
73
|
+
this.clearSubscribers();
|
|
74
|
+
return EmitResult.OK;
|
|
75
|
+
}
|
|
76
|
+
/** Attempts to fail this sink. */
|
|
77
|
+
tryEmitError(error) {
|
|
78
|
+
if (this.state !== "pending") return EmitResult.FAIL_TERMINATED;
|
|
79
|
+
this.state = "error";
|
|
80
|
+
this.errorValue = error;
|
|
81
|
+
const subscribers = this.subscribers;
|
|
82
|
+
if (subscribers instanceof Set) for (const subscriber of subscribers) subscriber.error(error);
|
|
83
|
+
else if (subscribers) subscribers.error(error);
|
|
84
|
+
this.clearSubscribers();
|
|
85
|
+
return EmitResult.OK;
|
|
86
|
+
}
|
|
87
|
+
/** Emits a value or delegates failure handling to the provided handler. */
|
|
88
|
+
emitValue(value, handler = EmitFailureHandlers.FAIL_FAST) {
|
|
89
|
+
const result = this.tryEmitValue(value);
|
|
90
|
+
if (result !== EmitResult.FAIL_TERMINATED) emitOrThrow(SignalType.NEXT, () => result, handler);
|
|
91
|
+
}
|
|
92
|
+
/** Completes this sink or delegates failure handling to the provided handler. */
|
|
93
|
+
emitEmpty(handler = EmitFailureHandlers.FAIL_FAST) {
|
|
94
|
+
const result = this.tryEmitEmpty();
|
|
95
|
+
if (result !== EmitResult.FAIL_TERMINATED) emitOrThrow(SignalType.COMPLETE, () => result, handler);
|
|
96
|
+
}
|
|
97
|
+
/** Fails this sink or delegates failure handling to the provided handler. */
|
|
98
|
+
emitError(error, handler = EmitFailureHandlers.FAIL_FAST) {
|
|
99
|
+
const result = this.tryEmitError(error);
|
|
100
|
+
if (result !== EmitResult.FAIL_TERMINATED) emitOrThrow(SignalType.ERROR, () => result, handler, error);
|
|
101
|
+
}
|
|
102
|
+
/** Returns the current number of active subscribers. */
|
|
103
|
+
currentSubscriberCount() {
|
|
104
|
+
return sinkSubscriberCount(this.subscribers);
|
|
105
|
+
}
|
|
106
|
+
/** Handles an emission failure and returns false to fail fast by default. */
|
|
107
|
+
onEmitFailure(_signalType, _emitResult) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
/** Adds a subscriber queue and removes it again when its subscription is cancelled. */
|
|
111
|
+
addSubscriber(queue, signal) {
|
|
112
|
+
this.subscribers = addSinkSubscriber(this.subscribers, queue);
|
|
113
|
+
signal.addEventListener("abort", () => this.removeSubscriber(queue), { once: true });
|
|
114
|
+
}
|
|
115
|
+
/** Removes a subscriber queue and releases the set when it becomes empty. */
|
|
116
|
+
removeSubscriber(queue) {
|
|
117
|
+
this.subscribers = removeSinkSubscriber(this.subscribers, queue);
|
|
118
|
+
}
|
|
119
|
+
/** Clears and releases all active subscriber queues. */
|
|
120
|
+
clearSubscribers() {
|
|
121
|
+
clearSinkSubscribers(this.subscribers);
|
|
122
|
+
this.subscribers = void 0;
|
|
123
|
+
}
|
|
124
|
+
/** Replays the current state into a newly subscribed queue. */
|
|
125
|
+
replay(queue) {
|
|
126
|
+
switch (this.state) {
|
|
127
|
+
case "value":
|
|
128
|
+
queue.push(this.value);
|
|
129
|
+
queue.complete();
|
|
130
|
+
break;
|
|
131
|
+
case "empty":
|
|
132
|
+
queue.complete();
|
|
133
|
+
break;
|
|
134
|
+
case "error":
|
|
135
|
+
queue.error(this.errorValue);
|
|
136
|
+
break;
|
|
137
|
+
case "pending": break;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
//#endregion
|
|
142
|
+
export { DefaultOneSink };
|
|
143
|
+
|
|
144
|
+
//# sourceMappingURL=one.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"one.js","names":[],"sources":["../../src/sinks/one.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Sink specifications and default browser-oriented sink implementations.\n */\nimport {AsyncQueue} from \"@/internal/async-queue.js\";\nimport {Mono} from \"@/publisher/mono.js\";\nimport {SignalType} from \"@/signal/signal-type.js\";\nimport {\n addSinkSubscriber,\n clearSinkSubscribers,\n removeSinkSubscriber,\n sinkSubscriberCount,\n type SinkSubscribers\n} from \"@/sinks/subscribers.js\";\nimport {type EmitFailureHandler, EmitFailureHandlers, emitOrThrow, EmitResult, type OneSink} from \"@/sinks/types.js\";\n\n/** Terminal or pending state held by a one-valued sink. */\ntype OneState = \"pending\" | \"empty\" | \"value\" | \"error\";\n\n/** Default replaying implementation for `Sinks.one()` and `Sinks.empty()`. */\nexport class DefaultOneSink<T> implements OneSink<T> {\n /** Current terminal or pending state of the sink. */\n private state: OneState = \"pending\";\n /** Stored value replayed to late subscribers after successful termination. */\n private value: T | undefined;\n /** Stored error replayed to late subscribers after failed termination. */\n private errorValue: unknown;\n /** Active subscriber queues waiting for the terminal result, created only when needed. */\n private subscribers: SinkSubscribers<T> | undefined;\n\n /** Returns the Mono view of this sink. */\n public asMono(): Mono<T> {\n return new Mono(signal => {\n const queue = new AsyncQueue<T>(signal);\n this.replay(queue);\n if (this.state === \"pending\") {\n this.addSubscriber(queue, signal);\n }\n return queue;\n });\n }\n\n /** Attempts to emit a value and complete this sink. */\n public tryEmitValue(value: T): EmitResult {\n if (this.state !== \"pending\") {\n return EmitResult.FAIL_TERMINATED;\n }\n this.state = \"value\";\n this.value = value;\n const subscribers = this.subscribers;\n if (subscribers instanceof Set) {\n for (const subscriber of subscribers) {\n subscriber.push(value);\n subscriber.complete();\n }\n } else if (subscribers) {\n subscribers.push(value);\n subscribers.complete();\n }\n this.clearSubscribers();\n return EmitResult.OK;\n }\n\n /** Attempts to complete this sink without a value. */\n public tryEmitEmpty(): EmitResult {\n if (this.state !== \"pending\") {\n return EmitResult.FAIL_TERMINATED;\n }\n this.state = \"empty\";\n const subscribers = this.subscribers;\n if (subscribers instanceof Set) {\n for (const subscriber of subscribers) {\n subscriber.complete();\n }\n } else if (subscribers) {\n subscribers.complete();\n }\n this.clearSubscribers();\n return EmitResult.OK;\n }\n\n /** Attempts to fail this sink. */\n public tryEmitError(error: unknown): EmitResult {\n if (this.state !== \"pending\") {\n return EmitResult.FAIL_TERMINATED;\n }\n this.state = \"error\";\n this.errorValue = error;\n const subscribers = this.subscribers;\n if (subscribers instanceof Set) {\n for (const subscriber of subscribers) {\n subscriber.error(error);\n }\n } else if (subscribers) {\n subscribers.error(error);\n }\n this.clearSubscribers();\n return EmitResult.OK;\n }\n\n /** Emits a value or delegates failure handling to the provided handler. */\n public emitValue(value: T, handler: EmitFailureHandler = EmitFailureHandlers.FAIL_FAST): void {\n const result = this.tryEmitValue(value);\n if (result !== EmitResult.FAIL_TERMINATED) {\n emitOrThrow(SignalType.NEXT, () => result, handler);\n }\n }\n\n /** Completes this sink or delegates failure handling to the provided handler. */\n public emitEmpty(handler: EmitFailureHandler = EmitFailureHandlers.FAIL_FAST): void {\n const result = this.tryEmitEmpty();\n if (result !== EmitResult.FAIL_TERMINATED) {\n emitOrThrow(SignalType.COMPLETE, () => result, handler);\n }\n }\n\n /** Fails this sink or delegates failure handling to the provided handler. */\n public emitError(error: unknown, handler: EmitFailureHandler = EmitFailureHandlers.FAIL_FAST): void {\n const result = this.tryEmitError(error);\n if (result !== EmitResult.FAIL_TERMINATED) {\n emitOrThrow(SignalType.ERROR, () => result, handler, error);\n }\n }\n\n /** Returns the current number of active subscribers. */\n public currentSubscriberCount(): number {\n return sinkSubscriberCount(this.subscribers);\n }\n\n /** Handles an emission failure and returns false to fail fast by default. */\n public onEmitFailure(_signalType: SignalType, _emitResult: EmitResult): boolean {\n return false;\n }\n\n /** Adds a subscriber queue and removes it again when its subscription is cancelled. */\n private addSubscriber(queue: AsyncQueue<T>, signal: AbortSignal): void {\n this.subscribers = addSinkSubscriber(this.subscribers, queue);\n signal.addEventListener(\"abort\", () => this.removeSubscriber(queue), {once: true});\n }\n\n /** Removes a subscriber queue and releases the set when it becomes empty. */\n private removeSubscriber(queue: AsyncQueue<T>): void {\n this.subscribers = removeSinkSubscriber(this.subscribers, queue);\n }\n\n /** Clears and releases all active subscriber queues. */\n private clearSubscribers(): void {\n clearSinkSubscribers(this.subscribers);\n this.subscribers = undefined;\n }\n\n /** Replays the current state into a newly subscribed queue. */\n private replay(queue: AsyncQueue<T>): void {\n switch (this.state) {\n case \"value\":\n queue.push(this.value as T);\n queue.complete();\n break;\n case \"empty\":\n queue.complete();\n break;\n case \"error\":\n queue.error(this.errorValue);\n break;\n case \"pending\":\n break;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAoBA,IAAa,iBAAb,MAAqD;;;;;GAEjD;GAA0B;;;;;GAE1B;;;;;;GAEA;;;;;;GAEA;;;;;CAGA,SAAyB;EACrB,OAAO,IAAI,MAAK,WAAU;GACtB,MAAM,QAAQ,IAAI,WAAc,MAAM;GACtC,KAAK,OAAO,KAAK;GACjB,IAAI,KAAK,UAAU,WACf,KAAK,cAAc,OAAO,MAAM;GAEpC,OAAO;EACX,CAAC;CACL;;CAGA,aAAoB,OAAsB;EACtC,IAAI,KAAK,UAAU,WACf,OAAO,WAAW;EAEtB,KAAK,QAAQ;EACb,KAAK,QAAQ;EACb,MAAM,cAAc,KAAK;EACzB,IAAI,uBAAuB,KACvB,KAAK,MAAM,cAAc,aAAa;GAClC,WAAW,KAAK,KAAK;GACrB,WAAW,SAAS;EACxB;OACG,IAAI,aAAa;GACpB,YAAY,KAAK,KAAK;GACtB,YAAY,SAAS;EACzB;EACA,KAAK,iBAAiB;EACtB,OAAO,WAAW;CACtB;;CAGA,eAAkC;EAC9B,IAAI,KAAK,UAAU,WACf,OAAO,WAAW;EAEtB,KAAK,QAAQ;EACb,MAAM,cAAc,KAAK;EACzB,IAAI,uBAAuB,KACvB,KAAK,MAAM,cAAc,aACrB,WAAW,SAAS;OAErB,IAAI,aACP,YAAY,SAAS;EAEzB,KAAK,iBAAiB;EACtB,OAAO,WAAW;CACtB;;CAGA,aAAoB,OAA4B;EAC5C,IAAI,KAAK,UAAU,WACf,OAAO,WAAW;EAEtB,KAAK,QAAQ;EACb,KAAK,aAAa;EAClB,MAAM,cAAc,KAAK;EACzB,IAAI,uBAAuB,KACvB,KAAK,MAAM,cAAc,aACrB,WAAW,MAAM,KAAK;OAEvB,IAAI,aACP,YAAY,MAAM,KAAK;EAE3B,KAAK,iBAAiB;EACtB,OAAO,WAAW;CACtB;;CAGA,UAAiB,OAAU,UAA8B,oBAAoB,WAAiB;EAC1F,MAAM,SAAS,KAAK,aAAa,KAAK;EACtC,IAAI,WAAW,WAAW,iBACtB,YAAY,WAAW,YAAY,QAAQ,OAAO;CAE1D;;CAGA,UAAiB,UAA8B,oBAAoB,WAAiB;EAChF,MAAM,SAAS,KAAK,aAAa;EACjC,IAAI,WAAW,WAAW,iBACtB,YAAY,WAAW,gBAAgB,QAAQ,OAAO;CAE9D;;CAGA,UAAiB,OAAgB,UAA8B,oBAAoB,WAAiB;EAChG,MAAM,SAAS,KAAK,aAAa,KAAK;EACtC,IAAI,WAAW,WAAW,iBACtB,YAAY,WAAW,aAAa,QAAQ,SAAS,KAAK;CAElE;;CAGA,yBAAwC;EACpC,OAAO,oBAAoB,KAAK,WAAW;CAC/C;;CAGA,cAAqB,aAAyB,aAAkC;EAC5E,OAAO;CACX;;CAGA,cAAsB,OAAsB,QAA2B;EACnE,KAAK,cAAc,kBAAkB,KAAK,aAAa,KAAK;EAC5D,OAAO,iBAAiB,eAAe,KAAK,iBAAiB,KAAK,GAAG,EAAC,MAAM,KAAI,CAAC;CACrF;;CAGA,iBAAyB,OAA4B;EACjD,KAAK,cAAc,qBAAqB,KAAK,aAAa,KAAK;CACnE;;CAGA,mBAAiC;EAC7B,qBAAqB,KAAK,WAAW;EACrC,KAAK,cAAc;CACvB;;CAGA,OAAe,OAA4B;EACvC,QAAQ,KAAK,OAAb;GACI,KAAK;IACD,MAAM,KAAK,KAAK,KAAU;IAC1B,MAAM,SAAS;IACf;GACJ,KAAK;IACD,MAAM,SAAS;IACf;GACJ,KAAK;IACD,MAAM,MAAM,KAAK,UAAU;IAC3B;GACJ,KAAK,WACD;EACR;CACJ;AACJ"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EmptySink, ManySink, ManySpec, ManyWithUpstreamSpec, OneSink } from "./types.js";
|
|
2
|
+
/** Builder tree for unsafe sinks that can subscribe to upstream publishers. */
|
|
3
|
+
declare const unsafeSpec: {
|
|
4
|
+
/** Creates an empty sink that can only terminate. */
|
|
5
|
+
empty<T>(): EmptySink<T>;
|
|
6
|
+
/** Creates a one-valued sink that replays its terminal result. */
|
|
7
|
+
one<T>(): OneSink<T>;
|
|
8
|
+
/** Returns builders for many-valued sinks. */
|
|
9
|
+
many(): ManySpec;
|
|
10
|
+
/** Returns builders for many-valued sinks that can subscribe to one upstream publisher. */
|
|
11
|
+
manyWithUpstream(): ManyWithUpstreamSpec;
|
|
12
|
+
};
|
|
13
|
+
/** Public Sinks factory facade. */
|
|
14
|
+
export declare const Sinks: Readonly<{
|
|
15
|
+
/** Creates an empty sink that can only terminate. */
|
|
16
|
+
empty<T>(): EmptySink<T>;
|
|
17
|
+
/** Creates a one-valued sink that replays its terminal result. */
|
|
18
|
+
one<T>(): OneSink<T>;
|
|
19
|
+
/** Returns builders for many-valued sinks. */
|
|
20
|
+
many(): ManySpec;
|
|
21
|
+
/** Returns unsafe sink builders. */
|
|
22
|
+
unsafe(): typeof unsafeSpec;
|
|
23
|
+
}>;
|
|
24
|
+
export type { ManySink };
|
|
25
|
+
//# sourceMappingURL=specs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specs.d.ts","sourceRoot":"","sources":["../../src/sinks/specs.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,oBAAoB,EAEpB,OAAO,EAGR,MAAM,kBAAkB,CAAC;AAqF1B,+EAA+E;AAC/E,QAAA,MAAM,UAAU,EAAE;IACd,qDAAqD;IACrD,KAAK,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC;IACzB,kEAAkE;IAClE,GAAG,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,8CAA8C;IAC9C,IAAI,IAAI,QAAQ,CAAC;IACjB,2FAA2F;IAC3F,gBAAgB,IAAI,oBAAoB,CAAC;CAqB3C,CAAC;AAEH,mCAAmC;AACnC,eAAO,MAAM,KAAK;IACd,qDAAqD;UAC/C,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC;IAIxB,kEAAkE;QAC9D,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC;IAIpB,8CAA8C;YACtC,QAAQ;IAIhB,oCAAoC;cAC1B,OAAO,UAAU;EAG7B,CAAC;AAEH,YAAY,EAAC,QAAQ,EAAC,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { DefaultManySink } from "./many.js";
|
|
2
|
+
import { DefaultOneSink } from "./one.js";
|
|
3
|
+
//#region src/sinks/specs.ts
|
|
4
|
+
/**
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* Sink specifications and default browser-oriented sink implementations.
|
|
7
|
+
*/
|
|
8
|
+
/** Shared builders for unicast many-valued sinks. */
|
|
9
|
+
var unicastSpec = Object.freeze({
|
|
10
|
+
/** Creates a unicast sink with backpressure buffering. */
|
|
11
|
+
onBackpressureBuffer() {
|
|
12
|
+
return new DefaultManySink({ mode: "unicast" });
|
|
13
|
+
},
|
|
14
|
+
/** Creates a unicast sink that fails emission when demand cannot be honored. */
|
|
15
|
+
onBackpressureError() {
|
|
16
|
+
return new DefaultManySink({ mode: "unicast-error" });
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
/** Shared builders for multicast many-valued sinks. */
|
|
20
|
+
var multicastSpec = Object.freeze({
|
|
21
|
+
/** Creates a multicast sink that buffers when subscribers are temporarily absent. */
|
|
22
|
+
onBackpressureBuffer() {
|
|
23
|
+
return new DefaultManySink({ mode: "multicast-buffer" });
|
|
24
|
+
},
|
|
25
|
+
/** Creates a multicast sink that fails emission when no subscriber can receive it. */
|
|
26
|
+
directAllOrNothing() {
|
|
27
|
+
return new DefaultManySink({ mode: "multicast-direct" });
|
|
28
|
+
},
|
|
29
|
+
/** Creates a multicast sink that emits to currently available subscribers. */
|
|
30
|
+
directBestEffort() {
|
|
31
|
+
return new DefaultManySink({ mode: "multicast-direct" });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
/** Shared builders for replaying many-valued sinks. */
|
|
35
|
+
var replaySpec = Object.freeze({
|
|
36
|
+
/** Creates a replay sink retaining every emitted value. */
|
|
37
|
+
all() {
|
|
38
|
+
return new DefaultManySink({ mode: "replay" });
|
|
39
|
+
},
|
|
40
|
+
/** Creates a replay sink retaining at most `historySize` values. */
|
|
41
|
+
limit(historySize) {
|
|
42
|
+
if (!Number.isInteger(historySize) || historySize <= 0) throw new RangeError("historySize must be a strictly positive integer");
|
|
43
|
+
return new DefaultManySink({
|
|
44
|
+
mode: "replay",
|
|
45
|
+
replayLimit: historySize
|
|
46
|
+
});
|
|
47
|
+
},
|
|
48
|
+
/** Creates a replay sink retaining only the latest emitted value. */
|
|
49
|
+
latest() {
|
|
50
|
+
return new DefaultManySink({
|
|
51
|
+
mode: "replay",
|
|
52
|
+
replayLimit: 1
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
/** Creates a replay sink with an initial default latest value. */
|
|
56
|
+
latestOrDefault(value) {
|
|
57
|
+
return new DefaultManySink({
|
|
58
|
+
mode: "replay",
|
|
59
|
+
replayLimit: 1,
|
|
60
|
+
latestDefault: value
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
/** Shared builder tree for many-valued sink variants. */
|
|
65
|
+
var manySpec = Object.freeze({
|
|
66
|
+
/** Returns builders for unicast many-valued sinks. */
|
|
67
|
+
unicast() {
|
|
68
|
+
return unicastSpec;
|
|
69
|
+
},
|
|
70
|
+
/** Returns builders for multicast many-valued sinks. */
|
|
71
|
+
multicast() {
|
|
72
|
+
return multicastSpec;
|
|
73
|
+
},
|
|
74
|
+
/** Returns builders for replaying many-valued sinks. */
|
|
75
|
+
replay() {
|
|
76
|
+
return replaySpec;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
/** Shared unsafe builders for many-valued sinks that subscribe to upstream publishers. */
|
|
80
|
+
var manyWithUpstreamSpec = Object.freeze({
|
|
81
|
+
/** Creates a multicast sink that buffers and can subscribe to one upstream publisher. */
|
|
82
|
+
multicastOnBackpressureBuffer() {
|
|
83
|
+
return new DefaultManySink({ mode: "multicast-buffer" });
|
|
84
|
+
} });
|
|
85
|
+
/** Builder tree for unsafe sinks that can subscribe to upstream publishers. */
|
|
86
|
+
var unsafeSpec = Object.freeze({
|
|
87
|
+
/** Creates an empty sink that can only terminate. */
|
|
88
|
+
empty() {
|
|
89
|
+
return new DefaultOneSink();
|
|
90
|
+
},
|
|
91
|
+
/** Creates a one-valued sink that replays its terminal result. */
|
|
92
|
+
one() {
|
|
93
|
+
return new DefaultOneSink();
|
|
94
|
+
},
|
|
95
|
+
/** Returns builders for many-valued sinks. */
|
|
96
|
+
many() {
|
|
97
|
+
return manySpec;
|
|
98
|
+
},
|
|
99
|
+
/** Returns builders for many-valued sinks that can subscribe to one upstream publisher. */
|
|
100
|
+
manyWithUpstream() {
|
|
101
|
+
return manyWithUpstreamSpec;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
/** Public Sinks factory facade. */
|
|
105
|
+
var Sinks = Object.freeze({
|
|
106
|
+
/** Creates an empty sink that can only terminate. */
|
|
107
|
+
empty() {
|
|
108
|
+
return new DefaultOneSink();
|
|
109
|
+
},
|
|
110
|
+
/** Creates a one-valued sink that replays its terminal result. */
|
|
111
|
+
one() {
|
|
112
|
+
return new DefaultOneSink();
|
|
113
|
+
},
|
|
114
|
+
/** Returns builders for many-valued sinks. */
|
|
115
|
+
many() {
|
|
116
|
+
return manySpec;
|
|
117
|
+
},
|
|
118
|
+
/** Returns unsafe sink builders. */
|
|
119
|
+
unsafe() {
|
|
120
|
+
return unsafeSpec;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
//#endregion
|
|
124
|
+
export { Sinks };
|
|
125
|
+
|
|
126
|
+
//# sourceMappingURL=specs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"specs.js","names":[],"sources":["../../src/sinks/specs.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Sink specifications and default browser-oriented sink implementations.\n */\nimport {DefaultManySink} from \"@/sinks/many.js\";\nimport {DefaultOneSink} from \"@/sinks/one.js\";\nimport type {\n EmptySink,\n ManySink,\n ManySpec,\n ManyWithUpstreamSpec,\n MulticastSpec,\n OneSink,\n ReplaySpec,\n UnicastSpec\n} from \"@/sinks/types.js\";\n\n/** Shared builders for unicast many-valued sinks. */\nconst unicastSpec: UnicastSpec = Object.freeze({\n /** Creates a unicast sink with backpressure buffering. */\n onBackpressureBuffer<T>() {\n return new DefaultManySink<T>({mode: \"unicast\"});\n },\n\n /** Creates a unicast sink that fails emission when demand cannot be honored. */\n onBackpressureError<T>() {\n return new DefaultManySink<T>({mode: \"unicast-error\"});\n }\n});\n\n/** Shared builders for multicast many-valued sinks. */\nconst multicastSpec: MulticastSpec = Object.freeze({\n /** Creates a multicast sink that buffers when subscribers are temporarily absent. */\n onBackpressureBuffer<T>() {\n return new DefaultManySink<T>({mode: \"multicast-buffer\"});\n },\n\n /** Creates a multicast sink that fails emission when no subscriber can receive it. */\n directAllOrNothing<T>() {\n return new DefaultManySink<T>({mode: \"multicast-direct\"});\n },\n\n /** Creates a multicast sink that emits to currently available subscribers. */\n directBestEffort<T>() {\n return new DefaultManySink<T>({mode: \"multicast-direct\"});\n }\n});\n\n/** Shared builders for replaying many-valued sinks. */\nconst replaySpec: ReplaySpec = Object.freeze({\n /** Creates a replay sink retaining every emitted value. */\n all<T>() {\n return new DefaultManySink<T>({mode: \"replay\"});\n },\n\n /** Creates a replay sink retaining at most `historySize` values. */\n limit<T>(historySize: number) {\n if (!Number.isInteger(historySize) || historySize <= 0) {\n throw new RangeError(\"historySize must be a strictly positive integer\");\n }\n return new DefaultManySink<T>({mode: \"replay\", replayLimit: historySize});\n },\n\n /** Creates a replay sink retaining only the latest emitted value. */\n latest<T>() {\n return new DefaultManySink<T>({mode: \"replay\", replayLimit: 1});\n },\n\n /** Creates a replay sink with an initial default latest value. */\n latestOrDefault<T>(value: T) {\n return new DefaultManySink<T>({mode: \"replay\", replayLimit: 1, latestDefault: value});\n }\n});\n\n/** Shared builder tree for many-valued sink variants. */\nconst manySpec: ManySpec = Object.freeze({\n /** Returns builders for unicast many-valued sinks. */\n unicast(): UnicastSpec {\n return unicastSpec;\n },\n\n /** Returns builders for multicast many-valued sinks. */\n multicast(): MulticastSpec {\n return multicastSpec;\n },\n\n /** Returns builders for replaying many-valued sinks. */\n replay(): ReplaySpec {\n return replaySpec;\n }\n});\n\n/** Shared unsafe builders for many-valued sinks that subscribe to upstream publishers. */\nconst manyWithUpstreamSpec: ManyWithUpstreamSpec = Object.freeze({\n /** Creates a multicast sink that buffers and can subscribe to one upstream publisher. */\n multicastOnBackpressureBuffer<T>() {\n return new DefaultManySink<T>({mode: \"multicast-buffer\"});\n }\n});\n\n/** Builder tree for unsafe sinks that can subscribe to upstream publishers. */\nconst unsafeSpec: {\n /** Creates an empty sink that can only terminate. */\n empty<T>(): EmptySink<T>;\n /** Creates a one-valued sink that replays its terminal result. */\n one<T>(): OneSink<T>;\n /** Returns builders for many-valued sinks. */\n many(): ManySpec;\n /** Returns builders for many-valued sinks that can subscribe to one upstream publisher. */\n manyWithUpstream(): ManyWithUpstreamSpec;\n} = Object.freeze({\n /** Creates an empty sink that can only terminate. */\n empty<T>(): EmptySink<T> {\n return new DefaultOneSink<T>();\n },\n\n /** Creates a one-valued sink that replays its terminal result. */\n one<T>(): OneSink<T> {\n return new DefaultOneSink<T>();\n },\n\n /** Returns builders for many-valued sinks. */\n many(): ManySpec {\n return manySpec;\n },\n\n /** Returns builders for many-valued sinks that can subscribe to one upstream publisher. */\n manyWithUpstream(): ManyWithUpstreamSpec {\n return manyWithUpstreamSpec;\n }\n});\n\n/** Public Sinks factory facade. */\nexport const Sinks = Object.freeze({\n /** Creates an empty sink that can only terminate. */\n empty<T>(): EmptySink<T> {\n return new DefaultOneSink<T>();\n },\n\n /** Creates a one-valued sink that replays its terminal result. */\n one<T>(): OneSink<T> {\n return new DefaultOneSink<T>();\n },\n\n /** Returns builders for many-valued sinks. */\n many(): ManySpec {\n return manySpec;\n },\n\n /** Returns unsafe sink builders. */\n unsafe(): typeof unsafeSpec {\n return unsafeSpec;\n }\n});\n\nexport type {ManySink};\n"],"mappings":";;;;;;;;AAkBA,IAAM,cAA2B,OAAO,OAAO;;CAE3C,uBAA0B;EACtB,OAAO,IAAI,gBAAmB,EAAC,MAAM,UAAS,CAAC;CACnD;;CAGA,sBAAyB;EACrB,OAAO,IAAI,gBAAmB,EAAC,MAAM,gBAAe,CAAC;CACzD;AACJ,CAAC;;AAGD,IAAM,gBAA+B,OAAO,OAAO;;CAE/C,uBAA0B;EACtB,OAAO,IAAI,gBAAmB,EAAC,MAAM,mBAAkB,CAAC;CAC5D;;CAGA,qBAAwB;EACpB,OAAO,IAAI,gBAAmB,EAAC,MAAM,mBAAkB,CAAC;CAC5D;;CAGA,mBAAsB;EAClB,OAAO,IAAI,gBAAmB,EAAC,MAAM,mBAAkB,CAAC;CAC5D;AACJ,CAAC;;AAGD,IAAM,aAAyB,OAAO,OAAO;;CAEzC,MAAS;EACL,OAAO,IAAI,gBAAmB,EAAC,MAAM,SAAQ,CAAC;CAClD;;CAGA,MAAS,aAAqB;EAC1B,IAAI,CAAC,OAAO,UAAU,WAAW,KAAK,eAAe,GACjD,MAAM,IAAI,WAAW,iDAAiD;EAE1E,OAAO,IAAI,gBAAmB;GAAC,MAAM;GAAU,aAAa;EAAW,CAAC;CAC5E;;CAGA,SAAY;EACR,OAAO,IAAI,gBAAmB;GAAC,MAAM;GAAU,aAAa;EAAC,CAAC;CAClE;;CAGA,gBAAmB,OAAU;EACzB,OAAO,IAAI,gBAAmB;GAAC,MAAM;GAAU,aAAa;GAAG,eAAe;EAAK,CAAC;CACxF;AACJ,CAAC;;AAGD,IAAM,WAAqB,OAAO,OAAO;;CAErC,UAAuB;EACnB,OAAO;CACX;;CAGA,YAA2B;EACvB,OAAO;CACX;;CAGA,SAAqB;EACjB,OAAO;CACX;AACJ,CAAC;;AAGD,IAAM,uBAA6C,OAAO,OAAO;;AAE7D,gCAAmC;CAC/B,OAAO,IAAI,gBAAmB,EAAC,MAAM,mBAAkB,CAAC;AAC5D,EACJ,CAAC;;AAGD,IAAM,aASF,OAAO,OAAO;;CAEd,QAAyB;EACrB,OAAO,IAAI,eAAkB;CACjC;;CAGA,MAAqB;EACjB,OAAO,IAAI,eAAkB;CACjC;;CAGA,OAAiB;EACb,OAAO;CACX;;CAGA,mBAAyC;EACrC,OAAO;CACX;AACJ,CAAC;;AAGD,IAAa,QAAQ,OAAO,OAAO;;CAE/B,QAAyB;EACrB,OAAO,IAAI,eAAkB;CACjC;;CAGA,MAAqB;EACjB,OAAO,IAAI,eAAkB;CACjC;;CAGA,OAAiB;EACb,OAAO;CACX;;CAGA,SAA4B;EACxB,OAAO;CACX;AACJ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Compact subscriber storage shared by sink implementations.
|
|
4
|
+
*/
|
|
5
|
+
import type { AsyncQueue } from "../internal/async-queue.js";
|
|
6
|
+
/** Compact storage for one or many active sink subscriber queues. */
|
|
7
|
+
export type SinkSubscribers<T> = AsyncQueue<T> | Set<AsyncQueue<T>>;
|
|
8
|
+
/** Adds a queue without allocating a Set for the common single-subscriber case. */
|
|
9
|
+
export declare function addSinkSubscriber<T>(subscribers: SinkSubscribers<T> | undefined, queue: AsyncQueue<T>): SinkSubscribers<T>;
|
|
10
|
+
/** Removes a queue and releases multi-subscriber storage when it becomes empty. */
|
|
11
|
+
export declare function removeSinkSubscriber<T>(subscribers: SinkSubscribers<T> | undefined, queue: AsyncQueue<T>): SinkSubscribers<T> | undefined;
|
|
12
|
+
/** Clears multi-subscriber storage before the owner drops its reference. */
|
|
13
|
+
export declare function clearSinkSubscribers<T>(subscribers: SinkSubscribers<T> | undefined): void;
|
|
14
|
+
/** Returns the number of active queues in compact subscriber storage. */
|
|
15
|
+
export declare function sinkSubscriberCount<T>(subscribers: SinkSubscribers<T> | undefined): number;
|
|
16
|
+
//# sourceMappingURL=subscribers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribers.d.ts","sourceRoot":"","sources":["../../src/sinks/subscribers.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,2BAA2B,CAAC;AAE1D,qEAAqE;AACrE,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE,mFAAmF;AACnF,wBAAgB,iBAAiB,CAAC,CAAC,EAC/B,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,EAC3C,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GACrB,eAAe,CAAC,CAAC,CAAC,CASpB;AAED,mFAAmF;AACnF,wBAAgB,oBAAoB,CAAC,CAAC,EAClC,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,EAC3C,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GACrB,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,CAShC;AAED,4EAA4E;AAC5E,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAIzF;AAED,yEAAyE;AACzE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,WAAW,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,MAAM,CAK1F"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
//#region src/sinks/subscribers.ts
|
|
2
|
+
/** Adds a queue without allocating a Set for the common single-subscriber case. */
|
|
3
|
+
function addSinkSubscriber(subscribers, queue) {
|
|
4
|
+
if (subscribers === void 0) return queue;
|
|
5
|
+
if (subscribers instanceof Set) {
|
|
6
|
+
subscribers.add(queue);
|
|
7
|
+
return subscribers;
|
|
8
|
+
}
|
|
9
|
+
return subscribers === queue ? subscribers : /* @__PURE__ */ new Set([subscribers, queue]);
|
|
10
|
+
}
|
|
11
|
+
/** Removes a queue and releases multi-subscriber storage when it becomes empty. */
|
|
12
|
+
function removeSinkSubscriber(subscribers, queue) {
|
|
13
|
+
if (subscribers === void 0) return;
|
|
14
|
+
if (subscribers instanceof Set) {
|
|
15
|
+
subscribers.delete(queue);
|
|
16
|
+
return subscribers.size === 0 ? void 0 : subscribers;
|
|
17
|
+
}
|
|
18
|
+
return subscribers === queue ? void 0 : subscribers;
|
|
19
|
+
}
|
|
20
|
+
/** Clears multi-subscriber storage before the owner drops its reference. */
|
|
21
|
+
function clearSinkSubscribers(subscribers) {
|
|
22
|
+
if (subscribers instanceof Set) subscribers.clear();
|
|
23
|
+
}
|
|
24
|
+
/** Returns the number of active queues in compact subscriber storage. */
|
|
25
|
+
function sinkSubscriberCount(subscribers) {
|
|
26
|
+
if (subscribers === void 0) return 0;
|
|
27
|
+
return subscribers instanceof Set ? subscribers.size : 1;
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { addSinkSubscriber, clearSinkSubscribers, removeSinkSubscriber, sinkSubscriberCount };
|
|
31
|
+
|
|
32
|
+
//# sourceMappingURL=subscribers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribers.js","names":[],"sources":["../../src/sinks/subscribers.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Compact subscriber storage shared by sink implementations.\n */\nimport type {AsyncQueue} from \"@/internal/async-queue.js\";\n\n/** Compact storage for one or many active sink subscriber queues. */\nexport type SinkSubscribers<T> = AsyncQueue<T> | Set<AsyncQueue<T>>;\n\n/** Adds a queue without allocating a Set for the common single-subscriber case. */\nexport function addSinkSubscriber<T>(\n subscribers: SinkSubscribers<T> | undefined,\n queue: AsyncQueue<T>\n): SinkSubscribers<T> {\n if (subscribers === undefined) {\n return queue;\n }\n if (subscribers instanceof Set) {\n subscribers.add(queue);\n return subscribers;\n }\n return subscribers === queue ? subscribers : new Set([subscribers, queue]);\n}\n\n/** Removes a queue and releases multi-subscriber storage when it becomes empty. */\nexport function removeSinkSubscriber<T>(\n subscribers: SinkSubscribers<T> | undefined,\n queue: AsyncQueue<T>\n): SinkSubscribers<T> | undefined {\n if (subscribers === undefined) {\n return undefined;\n }\n if (subscribers instanceof Set) {\n subscribers.delete(queue);\n return subscribers.size === 0 ? undefined : subscribers;\n }\n return subscribers === queue ? undefined : subscribers;\n}\n\n/** Clears multi-subscriber storage before the owner drops its reference. */\nexport function clearSinkSubscribers<T>(subscribers: SinkSubscribers<T> | undefined): void {\n if (subscribers instanceof Set) {\n subscribers.clear();\n }\n}\n\n/** Returns the number of active queues in compact subscriber storage. */\nexport function sinkSubscriberCount<T>(subscribers: SinkSubscribers<T> | undefined): number {\n if (subscribers === undefined) {\n return 0;\n }\n return subscribers instanceof Set ? subscribers.size : 1;\n}\n"],"mappings":";;AAUA,SAAgB,kBACZ,aACA,OACkB;CAClB,IAAI,gBAAgB,QAChB,OAAO;CAEX,IAAI,uBAAuB,KAAK;EAC5B,YAAY,IAAI,KAAK;EACrB,OAAO;CACX;CACA,OAAO,gBAAgB,QAAQ,8BAAc,IAAI,IAAI,CAAC,aAAa,KAAK,CAAC;AAC7E;;AAGA,SAAgB,qBACZ,aACA,OAC8B;CAC9B,IAAI,gBAAgB,QAChB;CAEJ,IAAI,uBAAuB,KAAK;EAC5B,YAAY,OAAO,KAAK;EACxB,OAAO,YAAY,SAAS,IAAI,SAAY;CAChD;CACA,OAAO,gBAAgB,QAAQ,SAAY;AAC/C;;AAGA,SAAgB,qBAAwB,aAAmD;CACvF,IAAI,uBAAuB,KACvB,YAAY,MAAM;AAE1B;;AAGA,SAAgB,oBAAuB,aAAqD;CACxF,IAAI,gBAAgB,QAChB,OAAO;CAEX,OAAO,uBAAuB,MAAM,YAAY,OAAO;AAC3D"}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Sink specifications and default browser-oriented sink implementations.
|
|
4
|
+
*/
|
|
5
|
+
import type { Disposable } from "../core/types.js";
|
|
6
|
+
import type { Flux } from "../publisher/flux.js";
|
|
7
|
+
import type { Mono } from "../publisher/mono.js";
|
|
8
|
+
import type { PublisherInput } from "../publisher/types.js";
|
|
9
|
+
import { SignalType } from "../signal/signal-type.js";
|
|
10
|
+
/** Result of a sink emission attempt. */
|
|
11
|
+
export declare enum EmitResult {
|
|
12
|
+
/** Emission succeeded. */
|
|
13
|
+
OK = "OK",
|
|
14
|
+
/** Emission failed because the sink has already terminated. */
|
|
15
|
+
FAIL_TERMINATED = "FAIL_TERMINATED",
|
|
16
|
+
/** Emission failed because buffering capacity was exhausted. */
|
|
17
|
+
FAIL_OVERFLOW = "FAIL_OVERFLOW",
|
|
18
|
+
/** Emission failed because the sink was cancelled. */
|
|
19
|
+
FAIL_CANCELLED = "FAIL_CANCELLED",
|
|
20
|
+
/** Emission failed because concurrent emission was detected. */
|
|
21
|
+
FAIL_NON_SERIALIZED = "FAIL_NON_SERIALIZED",
|
|
22
|
+
/** Emission failed because no subscriber was present. */
|
|
23
|
+
FAIL_ZERO_SUBSCRIBER = "FAIL_ZERO_SUBSCRIBER"
|
|
24
|
+
}
|
|
25
|
+
/** Error thrown when an emitting API cannot recover from an emission failure. */
|
|
26
|
+
export declare class EmissionException extends Error {
|
|
27
|
+
/** Failed emission result that caused this exception. */
|
|
28
|
+
readonly reason: EmitResult;
|
|
29
|
+
/** Creates an emission exception for a failed result. */
|
|
30
|
+
constructor(reason: EmitResult, cause?: unknown);
|
|
31
|
+
}
|
|
32
|
+
/** Callback that decides whether a failed emission should be retried. */
|
|
33
|
+
export type EmitFailureHandler = (signalType: SignalType, emitResult: EmitResult) => boolean;
|
|
34
|
+
/** Built-in emission failure handlers. */
|
|
35
|
+
export declare const EmitFailureHandlers: {
|
|
36
|
+
/** Fails immediately without retrying. */
|
|
37
|
+
FAIL_FAST: () => boolean;
|
|
38
|
+
/** Retries non-serialized emissions until the busy-loop deadline expires. */
|
|
39
|
+
busyLooping(durationMs: number): EmitFailureHandler;
|
|
40
|
+
};
|
|
41
|
+
/** Sink that can only emit a terminal signal. */
|
|
42
|
+
export interface EmptySink<T> {
|
|
43
|
+
/** Returns the Mono view of this sink. */
|
|
44
|
+
asMono(): Mono<T>;
|
|
45
|
+
/** Returns current active subscriber count. */
|
|
46
|
+
currentSubscriberCount(): number;
|
|
47
|
+
/** Attempts to complete this sink. */
|
|
48
|
+
tryEmitEmpty(): EmitResult;
|
|
49
|
+
/** Attempts to fail this sink. */
|
|
50
|
+
tryEmitError(error: unknown): EmitResult;
|
|
51
|
+
/** Completes this sink using the provided failure handler. */
|
|
52
|
+
emitEmpty(handler?: EmitFailureHandler): void;
|
|
53
|
+
/** Fails this sink using the provided failure handler. */
|
|
54
|
+
emitError(error: unknown, handler?: EmitFailureHandler): void;
|
|
55
|
+
/** Handles an emission failure and returns true when the caller should retry. */
|
|
56
|
+
onEmitFailure(signalType: SignalType, emitResult: EmitResult): boolean;
|
|
57
|
+
}
|
|
58
|
+
/** Sink that can emit zero or one value followed by completion. */
|
|
59
|
+
export interface OneSink<T> extends EmptySink<T> {
|
|
60
|
+
/** Attempts to emit a value and complete this sink. */
|
|
61
|
+
tryEmitValue(value: T): EmitResult;
|
|
62
|
+
/** Emits a value using the provided failure handler. */
|
|
63
|
+
emitValue(value: T, handler?: EmitFailureHandler): void;
|
|
64
|
+
}
|
|
65
|
+
/** Sink that can emit multiple values and a terminal signal. */
|
|
66
|
+
export interface ManySink<T> {
|
|
67
|
+
/** Returns the Flux view of this sink. */
|
|
68
|
+
asFlux(): Flux<T>;
|
|
69
|
+
/** Attempts to emit a value. */
|
|
70
|
+
tryEmitNext(value: T): EmitResult;
|
|
71
|
+
/** Attempts to complete this sink. */
|
|
72
|
+
tryEmitComplete(): EmitResult;
|
|
73
|
+
/** Attempts to fail this sink. */
|
|
74
|
+
tryEmitError(error: unknown): EmitResult;
|
|
75
|
+
/** Emits a value using the provided failure handler. */
|
|
76
|
+
emitNext(value: T, handler?: EmitFailureHandler): void;
|
|
77
|
+
/** Completes this sink using the provided failure handler. */
|
|
78
|
+
emitComplete(handler?: EmitFailureHandler): void;
|
|
79
|
+
/** Fails this sink using the provided failure handler. */
|
|
80
|
+
emitError(error: unknown, handler?: EmitFailureHandler): void;
|
|
81
|
+
/** Returns current active subscriber count. */
|
|
82
|
+
currentSubscriberCount(): number;
|
|
83
|
+
/** Subscribes this sink to an upstream publisher. */
|
|
84
|
+
subscribeTo(source: PublisherInput<T>): void;
|
|
85
|
+
/** Handles an emission failure and returns true when the caller should retry. */
|
|
86
|
+
onEmitFailure(signalType: SignalType, emitResult: EmitResult): boolean;
|
|
87
|
+
}
|
|
88
|
+
/** Root builder for many-valued sink variants. */
|
|
89
|
+
export interface ManySpec {
|
|
90
|
+
/** Returns unicast sink builders. */
|
|
91
|
+
unicast(): UnicastSpec;
|
|
92
|
+
/** Returns multicast sink builders. */
|
|
93
|
+
multicast(): MulticastSpec;
|
|
94
|
+
/** Returns replay sink builders. */
|
|
95
|
+
replay(): ReplaySpec;
|
|
96
|
+
}
|
|
97
|
+
/** Builder for unicast many-valued sinks. */
|
|
98
|
+
export interface UnicastSpec {
|
|
99
|
+
/** Creates a unicast sink with backpressure buffering. */
|
|
100
|
+
onBackpressureBuffer<T>(): ManySink<T>;
|
|
101
|
+
/** Creates a unicast sink that fails when backpressure cannot be honored. */
|
|
102
|
+
onBackpressureError<T>(): ManySink<T>;
|
|
103
|
+
}
|
|
104
|
+
/** Builder for sinks that can subscribe to one upstream publisher. */
|
|
105
|
+
export interface ManyWithUpstreamSpec {
|
|
106
|
+
/** Creates a multicast sink that buffers and can subscribe to one upstream publisher. */
|
|
107
|
+
multicastOnBackpressureBuffer<T>(): ManySink<T>;
|
|
108
|
+
}
|
|
109
|
+
/** Builder for multicast many-valued sinks. */
|
|
110
|
+
export interface MulticastSpec {
|
|
111
|
+
/** Creates a multicast sink with backpressure buffering. */
|
|
112
|
+
onBackpressureBuffer<T>(): ManySink<T>;
|
|
113
|
+
/** Creates a direct multicast sink that fails when no subscriber is present. */
|
|
114
|
+
directAllOrNothing<T>(): ManySink<T>;
|
|
115
|
+
/** Creates a direct best-effort multicast sink. */
|
|
116
|
+
directBestEffort<T>(): ManySink<T>;
|
|
117
|
+
}
|
|
118
|
+
/** Builder for replaying many-valued sinks. */
|
|
119
|
+
export interface ReplaySpec {
|
|
120
|
+
/** Replays all emitted values to late subscribers. */
|
|
121
|
+
all<T>(): ManySink<T>;
|
|
122
|
+
/** Replays up to `historySize` values to late subscribers. */
|
|
123
|
+
limit<T>(historySize: number): ManySink<T>;
|
|
124
|
+
/** Replays only the latest value to late subscribers. */
|
|
125
|
+
latest<T>(): ManySink<T>;
|
|
126
|
+
/** Replays the latest value or the provided default before the first emission. */
|
|
127
|
+
latestOrDefault<T>(value: T): ManySink<T>;
|
|
128
|
+
}
|
|
129
|
+
/** Disposable type alias used by sink implementations. */
|
|
130
|
+
export type SinkDisposable = Disposable;
|
|
131
|
+
/** Repeatedly invokes an emission attempt or throws when failure is not recoverable. */
|
|
132
|
+
export declare function emitOrThrow(signalType: SignalType, emit: () => EmitResult, handler: EmitFailureHandler, cause?: unknown): void;
|
|
133
|
+
/** Returns true when the emission result is successful. */
|
|
134
|
+
export declare function isEmitSuccess(result: EmitResult): boolean;
|
|
135
|
+
/** Returns true when the emission result is a failure. */
|
|
136
|
+
export declare function isEmitFailure(result: EmitResult): boolean;
|
|
137
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sinks/types.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
|
+
import { SignalType } from "../signal/signal-type.js";
|
|
3
|
+
//#region src/sinks/types.ts
|
|
4
|
+
/** Result of a sink emission attempt. */
|
|
5
|
+
var EmitResult = /* @__PURE__ */ function(EmitResult) {
|
|
6
|
+
/** Emission succeeded. */
|
|
7
|
+
EmitResult["OK"] = "OK";
|
|
8
|
+
/** Emission failed because the sink has already terminated. */
|
|
9
|
+
EmitResult["FAIL_TERMINATED"] = "FAIL_TERMINATED";
|
|
10
|
+
/** Emission failed because buffering capacity was exhausted. */
|
|
11
|
+
EmitResult["FAIL_OVERFLOW"] = "FAIL_OVERFLOW";
|
|
12
|
+
/** Emission failed because the sink was cancelled. */
|
|
13
|
+
EmitResult["FAIL_CANCELLED"] = "FAIL_CANCELLED";
|
|
14
|
+
/** Emission failed because concurrent emission was detected. */
|
|
15
|
+
EmitResult["FAIL_NON_SERIALIZED"] = "FAIL_NON_SERIALIZED";
|
|
16
|
+
/** Emission failed because no subscriber was present. */
|
|
17
|
+
EmitResult["FAIL_ZERO_SUBSCRIBER"] = "FAIL_ZERO_SUBSCRIBER";
|
|
18
|
+
return EmitResult;
|
|
19
|
+
}({});
|
|
20
|
+
/** Error thrown when an emitting API cannot recover from an emission failure. */
|
|
21
|
+
var EmissionException = class extends Error {
|
|
22
|
+
/** Creates an emission exception for a failed result. */
|
|
23
|
+
constructor(reason, cause) {
|
|
24
|
+
super(cause === void 0 ? `Emission failed with ${reason}` : `Emission failed with ${reason}: ${String(cause)}`);
|
|
25
|
+
_defineProperty(
|
|
26
|
+
this,
|
|
27
|
+
/** Failed emission result that caused this exception. */
|
|
28
|
+
"reason",
|
|
29
|
+
void 0
|
|
30
|
+
);
|
|
31
|
+
this.reason = reason;
|
|
32
|
+
this.name = "EmissionException";
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
/** Built-in emission failure handlers. */
|
|
36
|
+
var EmitFailureHandlers = {
|
|
37
|
+
/** Fails immediately without retrying. */
|
|
38
|
+
FAIL_FAST: () => false,
|
|
39
|
+
/** Retries non-serialized emissions until the busy-loop deadline expires. */
|
|
40
|
+
busyLooping(durationMs) {
|
|
41
|
+
return (signalType, emitResult) => {
|
|
42
|
+
const deadline = Date.now() + durationMs;
|
|
43
|
+
return signalType !== SignalType.ERROR && emitResult === "FAIL_NON_SERIALIZED" && Date.now() < deadline;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
/** Repeatedly invokes an emission attempt or throws when failure is not recoverable. */
|
|
48
|
+
function emitOrThrow(signalType, emit, handler, cause) {
|
|
49
|
+
for (;;) {
|
|
50
|
+
const result = emit();
|
|
51
|
+
if (result === "OK") return;
|
|
52
|
+
if (!handler(signalType, result)) throw new EmissionException(result, cause);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { EmissionException, EmitFailureHandlers, EmitResult, emitOrThrow };
|
|
57
|
+
|
|
58
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../src/sinks/types.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Sink specifications and default browser-oriented sink implementations.\n */\nimport type {Disposable} from \"@/core/types.js\";\nimport type {Flux} from \"@/publisher/flux.js\";\nimport type {Mono} from \"@/publisher/mono.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {SignalType} from \"@/signal/signal-type.js\";\n\n/** Result of a sink emission attempt. */\nexport enum EmitResult {\n /** Emission succeeded. */\n OK = \"OK\",\n /** Emission failed because the sink has already terminated. */\n FAIL_TERMINATED = \"FAIL_TERMINATED\",\n /** Emission failed because buffering capacity was exhausted. */\n FAIL_OVERFLOW = \"FAIL_OVERFLOW\",\n /** Emission failed because the sink was cancelled. */\n FAIL_CANCELLED = \"FAIL_CANCELLED\",\n /** Emission failed because concurrent emission was detected. */\n FAIL_NON_SERIALIZED = \"FAIL_NON_SERIALIZED\",\n /** Emission failed because no subscriber was present. */\n FAIL_ZERO_SUBSCRIBER = \"FAIL_ZERO_SUBSCRIBER\"\n}\n\n/** Error thrown when an emitting API cannot recover from an emission failure. */\nexport class EmissionException extends Error {\n /** Failed emission result that caused this exception. */\n public readonly reason: EmitResult;\n\n /** Creates an emission exception for a failed result. */\n public constructor(reason: EmitResult, cause?: unknown) {\n super(cause === undefined ? `Emission failed with ${reason}` : `Emission failed with ${reason}: ${String(cause)}`);\n this.reason = reason;\n this.name = \"EmissionException\";\n }\n}\n\n/** Callback that decides whether a failed emission should be retried. */\nexport type EmitFailureHandler = (signalType: SignalType, emitResult: EmitResult) => boolean;\n\n/** Built-in emission failure handlers. */\nexport const EmitFailureHandlers = {\n /** Fails immediately without retrying. */\n FAIL_FAST: () => false,\n\n /** Retries non-serialized emissions until the busy-loop deadline expires. */\n busyLooping(durationMs: number): EmitFailureHandler {\n return (signalType, emitResult) => {\n const deadline = Date.now() + durationMs;\n return signalType !== SignalType.ERROR && emitResult === EmitResult.FAIL_NON_SERIALIZED && Date.now() < deadline;\n };\n }\n};\n\n/** Sink that can only emit a terminal signal. */\nexport interface EmptySink<T> {\n /** Returns the Mono view of this sink. */\n asMono(): Mono<T>;\n\n /** Returns current active subscriber count. */\n currentSubscriberCount(): number;\n\n /** Attempts to complete this sink. */\n tryEmitEmpty(): EmitResult;\n\n /** Attempts to fail this sink. */\n tryEmitError(error: unknown): EmitResult;\n\n /** Completes this sink using the provided failure handler. */\n emitEmpty(handler?: EmitFailureHandler): void;\n\n /** Fails this sink using the provided failure handler. */\n emitError(error: unknown, handler?: EmitFailureHandler): void;\n\n /** Handles an emission failure and returns true when the caller should retry. */\n onEmitFailure(signalType: SignalType, emitResult: EmitResult): boolean;\n}\n\n/** Sink that can emit zero or one value followed by completion. */\nexport interface OneSink<T> extends EmptySink<T> {\n /** Attempts to emit a value and complete this sink. */\n tryEmitValue(value: T): EmitResult;\n\n /** Emits a value using the provided failure handler. */\n emitValue(value: T, handler?: EmitFailureHandler): void;\n}\n\n/** Sink that can emit multiple values and a terminal signal. */\nexport interface ManySink<T> {\n /** Returns the Flux view of this sink. */\n asFlux(): Flux<T>;\n\n /** Attempts to emit a value. */\n tryEmitNext(value: T): EmitResult;\n\n /** Attempts to complete this sink. */\n tryEmitComplete(): EmitResult;\n\n /** Attempts to fail this sink. */\n tryEmitError(error: unknown): EmitResult;\n\n /** Emits a value using the provided failure handler. */\n emitNext(value: T, handler?: EmitFailureHandler): void;\n\n /** Completes this sink using the provided failure handler. */\n emitComplete(handler?: EmitFailureHandler): void;\n\n /** Fails this sink using the provided failure handler. */\n emitError(error: unknown, handler?: EmitFailureHandler): void;\n\n /** Returns current active subscriber count. */\n currentSubscriberCount(): number;\n\n /** Subscribes this sink to an upstream publisher. */\n subscribeTo(source: PublisherInput<T>): void;\n\n /** Handles an emission failure and returns true when the caller should retry. */\n onEmitFailure(signalType: SignalType, emitResult: EmitResult): boolean;\n}\n\n/** Root builder for many-valued sink variants. */\nexport interface ManySpec {\n /** Returns unicast sink builders. */\n unicast(): UnicastSpec;\n\n /** Returns multicast sink builders. */\n multicast(): MulticastSpec;\n\n /** Returns replay sink builders. */\n replay(): ReplaySpec;\n}\n\n/** Builder for unicast many-valued sinks. */\nexport interface UnicastSpec {\n /** Creates a unicast sink with backpressure buffering. */\n onBackpressureBuffer<T>(): ManySink<T>;\n\n /** Creates a unicast sink that fails when backpressure cannot be honored. */\n onBackpressureError<T>(): ManySink<T>;\n}\n\n/** Builder for sinks that can subscribe to one upstream publisher. */\nexport interface ManyWithUpstreamSpec {\n /** Creates a multicast sink that buffers and can subscribe to one upstream publisher. */\n multicastOnBackpressureBuffer<T>(): ManySink<T>;\n}\n\n/** Builder for multicast many-valued sinks. */\nexport interface MulticastSpec {\n /** Creates a multicast sink with backpressure buffering. */\n onBackpressureBuffer<T>(): ManySink<T>;\n\n /** Creates a direct multicast sink that fails when no subscriber is present. */\n directAllOrNothing<T>(): ManySink<T>;\n\n /** Creates a direct best-effort multicast sink. */\n directBestEffort<T>(): ManySink<T>;\n}\n\n/** Builder for replaying many-valued sinks. */\nexport interface ReplaySpec {\n /** Replays all emitted values to late subscribers. */\n all<T>(): ManySink<T>;\n\n /** Replays up to `historySize` values to late subscribers. */\n limit<T>(historySize: number): ManySink<T>;\n\n /** Replays only the latest value to late subscribers. */\n latest<T>(): ManySink<T>;\n\n /** Replays the latest value or the provided default before the first emission. */\n latestOrDefault<T>(value: T): ManySink<T>;\n}\n\n/** Disposable type alias used by sink implementations. */\nexport type SinkDisposable = Disposable;\n\n/** Repeatedly invokes an emission attempt or throws when failure is not recoverable. */\nexport function emitOrThrow(\n signalType: SignalType,\n emit: () => EmitResult,\n handler: EmitFailureHandler,\n cause?: unknown\n): void {\n for (; ;) {\n const result = emit();\n if (result === EmitResult.OK) {\n return;\n }\n if (!handler(signalType, result)) {\n throw new EmissionException(result, cause);\n }\n }\n}\n\n/** Returns true when the emission result is successful. */\nexport function isEmitSuccess(result: EmitResult): boolean {\n return result === EmitResult.OK;\n}\n\n/** Returns true when the emission result is a failure. */\nexport function isEmitFailure(result: EmitResult): boolean {\n return result !== EmitResult.OK;\n}\n"],"mappings":";;;;AAWA,IAAY,aAAL,yBAAA,YAAA;;CAEH,WAAA,QAAA;;CAEA,WAAA,qBAAA;;CAEA,WAAA,mBAAA;;CAEA,WAAA,oBAAA;;CAEA,WAAA,yBAAA;;CAEA,WAAA,0BAAA;;AACJ,EAAA,CAAA,CAAA;;AAGA,IAAa,oBAAb,cAAuC,MAAM;;CAKzC,YAAmB,QAAoB,OAAiB;EACpD,MAAM,UAAU,SAAY,wBAAwB,WAAW,wBAAwB,OAAO,IAAI,OAAO,KAAK,GAAG;;;;GAJrH;;;EAKI,KAAK,SAAS;EACd,KAAK,OAAO;CAChB;AACJ;;AAMA,IAAa,sBAAsB;;CAE/B,iBAAiB;;CAGjB,YAAY,YAAwC;EAChD,QAAQ,YAAY,eAAe;GAC/B,MAAM,WAAW,KAAK,IAAI,IAAI;GAC9B,OAAO,eAAe,WAAW,SAAS,eAAA,yBAAiD,KAAK,IAAI,IAAI;EAC5G;CACJ;AACJ;;AA8HA,SAAgB,YACZ,YACA,MACA,SACA,OACI;CACJ,SAAU;EACN,MAAM,SAAS,KAAK;EACpB,IAAI,WAAA,MACA;EAEJ,IAAI,CAAC,QAAQ,YAAY,MAAM,GAC3B,MAAM,IAAI,kBAAkB,QAAQ,KAAK;CAEjD;AACJ"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* Context-aware subscriber contract.
|
|
4
|
+
*/
|
|
5
|
+
import type { Context } from "../context/context.js";
|
|
6
|
+
import type { Subscriber } from "./subscriber.js";
|
|
7
|
+
/** Subscriber variant that can expose a Reactor context to operators. */
|
|
8
|
+
export interface CoreSubscriber<T> extends Subscriber<T> {
|
|
9
|
+
/** Returns the subscriber context used for contextual operators. */
|
|
10
|
+
currentContext?(): Context;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=core-subscriber.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-subscriber.d.ts","sourceRoot":"","sources":["../../src/subscription/core-subscriber.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAClD,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAE7D,yEAAyE;AACzE,MAAM,WAAW,cAAc,CAAC,CAAC,CAAE,SAAQ,UAAU,CAAC,CAAC,CAAC;IACpD,oEAAoE;IACpE,cAAc,CAAC,IAAI,OAAO,CAAC;CAC9B"}
|