reactor-core-ts 2.1.6 → 3.2.2
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 +767 -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 +263 -0
- package/dist/publisher/operators/lifecycle.js.map +1 -0
- package/dist/publisher/operators/lift.d.ts +42 -0
- package/dist/publisher/operators/lift.d.ts.map +1 -0
- package/dist/publisher/operators/lift.js +343 -0
- package/dist/publisher/operators/lift.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 +81 -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 +75 -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 +100 -33
- 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,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":"AAAA;;;GAGG;AACH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,iBAAiB,CAAC;AAChD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAC,IAAI,EAAC,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AAM,cAAc,GAAG,UAAU,CAAC;AAExC,wFAAwF;AACxF,wBAAgB,WAAW,CACvB,UAAU,EAAE,UAAU,EACtB,IAAI,EAAE,MAAM,UAAU,EACtB,OAAO,EAAE,kBAAkB,EAC3B,KAAK,CAAC,EAAE,OAAO,GAChB,IAAI,CAUN;AAED,2DAA2D;AAC3D,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAEzD;AAED,0DAA0D;AAC1D,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAEzD"}
|
|
@@ -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"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { Context } from "../context/context.js";
|
|
2
|
+
import type { Flux } from "../publisher/flux.js";
|
|
3
|
+
import type { Subscriber } from "./subscriber.js";
|
|
4
|
+
import type { Subscription } from "./subscription.js";
|
|
5
|
+
/** Subscription implementation that drains a Flux only when demand is requested. */
|
|
6
|
+
export declare class IterableSubscription<T> implements Subscription {
|
|
7
|
+
/** Abort controller used to cancel the active source iterator. */
|
|
8
|
+
private readonly controller;
|
|
9
|
+
/** Lazily created async iterator over the backing Flux. */
|
|
10
|
+
private asyncIterator;
|
|
11
|
+
/** Lazily created synchronous iterator over the backing Flux. */
|
|
12
|
+
private syncIterator;
|
|
13
|
+
/** Tracks whether the source iterator has been assembled. */
|
|
14
|
+
private started;
|
|
15
|
+
/** Stores a synchronous source assembly failure until it can be signalled. */
|
|
16
|
+
private startFailure;
|
|
17
|
+
/** Tracks whether source assembly failed synchronously. */
|
|
18
|
+
private hasStartFailure;
|
|
19
|
+
/** Prefetched async result used to detect completion with zero demand. */
|
|
20
|
+
private pendingAsyncNext;
|
|
21
|
+
/** Prefetched sync result used to detect completion with zero demand. */
|
|
22
|
+
private pendingSyncNext;
|
|
23
|
+
/** Outstanding downstream demand. */
|
|
24
|
+
private requested;
|
|
25
|
+
/** Guards against concurrent drain loops. */
|
|
26
|
+
private draining;
|
|
27
|
+
/** Tracks downstream cancellation. */
|
|
28
|
+
private cancelled;
|
|
29
|
+
/** Tracks terminal completion or failure delivery. */
|
|
30
|
+
private terminated;
|
|
31
|
+
/** Source Flux drained by this subscription. */
|
|
32
|
+
private readonly flux;
|
|
33
|
+
/** Downstream subscriber receiving signals. */
|
|
34
|
+
private readonly subscriber;
|
|
35
|
+
/** Context used for the source iteration. */
|
|
36
|
+
private readonly context;
|
|
37
|
+
/** Creates a subscription for the provided Flux and subscriber. */
|
|
38
|
+
constructor(flux: Flux<T>, subscriber: Subscriber<T>, context: Context);
|
|
39
|
+
/** Starts source assembly without pulling any values from it. */
|
|
40
|
+
start(): void;
|
|
41
|
+
/** Delivers a synchronous source assembly failure after `onSubscribe`. */
|
|
42
|
+
deliverStartFailure(): void;
|
|
43
|
+
/** Requests more values from the backing iterator. */
|
|
44
|
+
request(n: number): void;
|
|
45
|
+
/** Cancels iteration and closes upstream resources. */
|
|
46
|
+
cancel(): void;
|
|
47
|
+
/** Drains the source while there is outstanding demand. */
|
|
48
|
+
private drain;
|
|
49
|
+
/** Drains a synchronous source without per-item promise allocation. */
|
|
50
|
+
private drainSync;
|
|
51
|
+
/** Returns true after delivering a terminal result. */
|
|
52
|
+
private deliverResult;
|
|
53
|
+
/** Returns the pending prefetched async result or asks the async iterator for the next item. */
|
|
54
|
+
private nextAsyncResult;
|
|
55
|
+
/** Returns the pending prefetched sync result or asks the sync iterator for the next item. */
|
|
56
|
+
private nextSyncResult;
|
|
57
|
+
/** Prefetches one item to discover terminal completion without extra demand. */
|
|
58
|
+
private lookAheadForTermination;
|
|
59
|
+
/** Prefetches one synchronous item to discover terminal completion without extra demand. */
|
|
60
|
+
private lookAheadForSyncTermination;
|
|
61
|
+
/** Closes active iterators and ignores cleanup failures after cancellation. */
|
|
62
|
+
private closeIterators;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=iterable-subscription.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"iterable-subscription.d.ts","sourceRoot":"","sources":["../../src/subscription/iterable-subscription.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAC,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAGlD,OAAO,KAAK,EAA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AC,EAAE,MAAM,GAAG,IAAI,CAkB9B;IAED,uDAAuD;IAChD,MAAM,IAAI,IAAI,CAOpB;IAED,2DAA2D;YAC7C,KAAK;IAyCnB,uEAAuE;IACvE,OAAO,CAAC,SAAS;IAYjB,uDAAuD;IACvD,OAAO,CAAC,aAAa;IAmBrB,gGAAgG;IAChG,OAAO,CAAC,eAAe;IASvB,8FAA8F;IAC9F,OAAO,CAAC,cAAc;IAStB,gFAAgF;IAChF,OAAO,CAAC,uBAAuB;IAgC/B,4FAA4F;IAC5F,OAAO,CAAC,2BAA2B;IAuBnC,+EAA+E;IAC/E,OAAO,CAAC,cAAc;CAYzB"}
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
|
+
import { doneResult, isAsyncIterable, resolvedDoneResult } from "../internal/iterable.js";
|
|
3
|
+
import { addCap, normalizeRequest } from "../core/demand.js";
|
|
4
|
+
import { scheduleMicrotask } from "../internal/microtask.js";
|
|
5
|
+
//#region src/subscription/iterable-subscription.ts
|
|
6
|
+
/**
|
|
7
|
+
* @packageDocumentation
|
|
8
|
+
* Reactive Streams subscription and subscriber contracts.
|
|
9
|
+
*/
|
|
10
|
+
/** Subscription implementation that drains a Flux only when demand is requested. */
|
|
11
|
+
var IterableSubscription = class {
|
|
12
|
+
/** Creates a subscription for the provided Flux and subscriber. */
|
|
13
|
+
constructor(flux, subscriber, context) {
|
|
14
|
+
_defineProperty(
|
|
15
|
+
this,
|
|
16
|
+
/** Abort controller used to cancel the active source iterator. */
|
|
17
|
+
"controller",
|
|
18
|
+
new AbortController()
|
|
19
|
+
);
|
|
20
|
+
_defineProperty(
|
|
21
|
+
this,
|
|
22
|
+
/** Lazily created async iterator over the backing Flux. */
|
|
23
|
+
"asyncIterator",
|
|
24
|
+
void 0
|
|
25
|
+
);
|
|
26
|
+
_defineProperty(
|
|
27
|
+
this,
|
|
28
|
+
/** Lazily created synchronous iterator over the backing Flux. */
|
|
29
|
+
"syncIterator",
|
|
30
|
+
void 0
|
|
31
|
+
);
|
|
32
|
+
_defineProperty(
|
|
33
|
+
this,
|
|
34
|
+
/** Tracks whether the source iterator has been assembled. */
|
|
35
|
+
"started",
|
|
36
|
+
false
|
|
37
|
+
);
|
|
38
|
+
_defineProperty(
|
|
39
|
+
this,
|
|
40
|
+
/** Stores a synchronous source assembly failure until it can be signalled. */
|
|
41
|
+
"startFailure",
|
|
42
|
+
void 0
|
|
43
|
+
);
|
|
44
|
+
_defineProperty(
|
|
45
|
+
this,
|
|
46
|
+
/** Tracks whether source assembly failed synchronously. */
|
|
47
|
+
"hasStartFailure",
|
|
48
|
+
false
|
|
49
|
+
);
|
|
50
|
+
_defineProperty(
|
|
51
|
+
this,
|
|
52
|
+
/** Prefetched async result used to detect completion with zero demand. */
|
|
53
|
+
"pendingAsyncNext",
|
|
54
|
+
void 0
|
|
55
|
+
);
|
|
56
|
+
_defineProperty(
|
|
57
|
+
this,
|
|
58
|
+
/** Prefetched sync result used to detect completion with zero demand. */
|
|
59
|
+
"pendingSyncNext",
|
|
60
|
+
void 0
|
|
61
|
+
);
|
|
62
|
+
_defineProperty(
|
|
63
|
+
this,
|
|
64
|
+
/** Outstanding downstream demand. */
|
|
65
|
+
"requested",
|
|
66
|
+
0
|
|
67
|
+
);
|
|
68
|
+
_defineProperty(
|
|
69
|
+
this,
|
|
70
|
+
/** Guards against concurrent drain loops. */
|
|
71
|
+
"draining",
|
|
72
|
+
false
|
|
73
|
+
);
|
|
74
|
+
_defineProperty(
|
|
75
|
+
this,
|
|
76
|
+
/** Tracks downstream cancellation. */
|
|
77
|
+
"cancelled",
|
|
78
|
+
false
|
|
79
|
+
);
|
|
80
|
+
_defineProperty(
|
|
81
|
+
this,
|
|
82
|
+
/** Tracks terminal completion or failure delivery. */
|
|
83
|
+
"terminated",
|
|
84
|
+
false
|
|
85
|
+
);
|
|
86
|
+
_defineProperty(
|
|
87
|
+
this,
|
|
88
|
+
/** Source Flux drained by this subscription. */
|
|
89
|
+
"flux",
|
|
90
|
+
void 0
|
|
91
|
+
);
|
|
92
|
+
_defineProperty(
|
|
93
|
+
this,
|
|
94
|
+
/** Downstream subscriber receiving signals. */
|
|
95
|
+
"subscriber",
|
|
96
|
+
void 0
|
|
97
|
+
);
|
|
98
|
+
_defineProperty(
|
|
99
|
+
this,
|
|
100
|
+
/** Context used for the source iteration. */
|
|
101
|
+
"context",
|
|
102
|
+
void 0
|
|
103
|
+
);
|
|
104
|
+
this.flux = flux;
|
|
105
|
+
this.subscriber = subscriber;
|
|
106
|
+
this.context = context;
|
|
107
|
+
}
|
|
108
|
+
/** Starts source assembly without pulling any values from it. */
|
|
109
|
+
start() {
|
|
110
|
+
if (this.started || this.cancelled || this.terminated) return;
|
|
111
|
+
this.started = true;
|
|
112
|
+
try {
|
|
113
|
+
const source = this.flux.iterate(this.controller.signal, this.context);
|
|
114
|
+
if (isAsyncIterable(source)) this.asyncIterator = source[Symbol.asyncIterator]();
|
|
115
|
+
else this.syncIterator = source[Symbol.iterator]();
|
|
116
|
+
} catch (error) {
|
|
117
|
+
this.startFailure = error;
|
|
118
|
+
this.hasStartFailure = true;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/** Delivers a synchronous source assembly failure after `onSubscribe`. */
|
|
122
|
+
deliverStartFailure() {
|
|
123
|
+
if (!this.hasStartFailure || this.cancelled || this.terminated) return;
|
|
124
|
+
this.hasStartFailure = false;
|
|
125
|
+
this.terminated = true;
|
|
126
|
+
this.subscriber.onError(this.startFailure);
|
|
127
|
+
}
|
|
128
|
+
/** Requests more values from the backing iterator. */
|
|
129
|
+
request(n) {
|
|
130
|
+
if (this.cancelled || this.terminated) return;
|
|
131
|
+
let request;
|
|
132
|
+
try {
|
|
133
|
+
request = normalizeRequest(n);
|
|
134
|
+
} catch (error) {
|
|
135
|
+
this.cancel();
|
|
136
|
+
this.subscriber.onError(error);
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
this.requested = addCap(this.requested, request);
|
|
140
|
+
if (this.hasStartFailure) {
|
|
141
|
+
this.deliverStartFailure();
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
this.drain();
|
|
145
|
+
}
|
|
146
|
+
/** Cancels iteration and closes upstream resources. */
|
|
147
|
+
cancel() {
|
|
148
|
+
if (this.cancelled || this.terminated) return;
|
|
149
|
+
this.cancelled = true;
|
|
150
|
+
this.controller.abort();
|
|
151
|
+
this.closeIterators();
|
|
152
|
+
}
|
|
153
|
+
/** Drains the source while there is outstanding demand. */
|
|
154
|
+
async drain() {
|
|
155
|
+
if (this.draining) return;
|
|
156
|
+
this.draining = true;
|
|
157
|
+
try {
|
|
158
|
+
this.start();
|
|
159
|
+
if (this.hasStartFailure) {
|
|
160
|
+
this.deliverStartFailure();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (this.syncIterator) {
|
|
164
|
+
this.drainSync();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
while (!this.cancelled && !this.terminated && this.requested > 0) {
|
|
168
|
+
const result = await this.nextAsyncResult();
|
|
169
|
+
if (this.cancelled || this.terminated) return;
|
|
170
|
+
if (this.deliverResult(result)) return;
|
|
171
|
+
}
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (!this.cancelled && !this.terminated) {
|
|
174
|
+
this.terminated = true;
|
|
175
|
+
this.subscriber.onError(error);
|
|
176
|
+
}
|
|
177
|
+
} finally {
|
|
178
|
+
this.draining = false;
|
|
179
|
+
if (!this.cancelled && !this.terminated && this.requested > 0) scheduleMicrotask(() => {
|
|
180
|
+
this.drain();
|
|
181
|
+
});
|
|
182
|
+
else if (!this.cancelled && !this.terminated && this.requested === 0) this.lookAheadForTermination();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
/** Drains a synchronous source without per-item promise allocation. */
|
|
186
|
+
drainSync() {
|
|
187
|
+
while (!this.cancelled && !this.terminated && this.requested > 0) {
|
|
188
|
+
const result = this.nextSyncResult();
|
|
189
|
+
if (this.cancelled || this.terminated) return;
|
|
190
|
+
if (this.deliverResult(result)) return;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/** Returns true after delivering a terminal result. */
|
|
194
|
+
deliverResult(result) {
|
|
195
|
+
if (result.done) {
|
|
196
|
+
this.terminated = true;
|
|
197
|
+
this.subscriber.onComplete();
|
|
198
|
+
return true;
|
|
199
|
+
}
|
|
200
|
+
if (this.requested !== Number.POSITIVE_INFINITY) this.requested -= 1;
|
|
201
|
+
try {
|
|
202
|
+
this.subscriber.onNext(result.value);
|
|
203
|
+
} catch (error) {
|
|
204
|
+
this.cancel();
|
|
205
|
+
this.subscriber.onError(error);
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
/** Returns the pending prefetched async result or asks the async iterator for the next item. */
|
|
211
|
+
nextAsyncResult() {
|
|
212
|
+
if (this.pendingAsyncNext) {
|
|
213
|
+
const pending = this.pendingAsyncNext;
|
|
214
|
+
this.pendingAsyncNext = void 0;
|
|
215
|
+
return pending;
|
|
216
|
+
}
|
|
217
|
+
return this.asyncIterator?.next() ?? resolvedDoneResult();
|
|
218
|
+
}
|
|
219
|
+
/** Returns the pending prefetched sync result or asks the sync iterator for the next item. */
|
|
220
|
+
nextSyncResult() {
|
|
221
|
+
if (this.pendingSyncNext) {
|
|
222
|
+
const pending = this.pendingSyncNext;
|
|
223
|
+
this.pendingSyncNext = void 0;
|
|
224
|
+
return pending;
|
|
225
|
+
}
|
|
226
|
+
return this.syncIterator?.next() ?? doneResult();
|
|
227
|
+
}
|
|
228
|
+
/** Prefetches one item to discover terminal completion without extra demand. */
|
|
229
|
+
lookAheadForTermination() {
|
|
230
|
+
if (this.syncIterator) {
|
|
231
|
+
this.lookAheadForSyncTermination();
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (!this.asyncIterator || this.pendingAsyncNext) return;
|
|
235
|
+
const pending = this.asyncIterator.next();
|
|
236
|
+
this.pendingAsyncNext = pending;
|
|
237
|
+
pending.then((result) => {
|
|
238
|
+
if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) return;
|
|
239
|
+
if (result.done) {
|
|
240
|
+
this.pendingAsyncNext = void 0;
|
|
241
|
+
this.terminated = true;
|
|
242
|
+
this.subscriber.onComplete();
|
|
243
|
+
}
|
|
244
|
+
}, (error) => {
|
|
245
|
+
if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) return;
|
|
246
|
+
this.pendingAsyncNext = void 0;
|
|
247
|
+
this.terminated = true;
|
|
248
|
+
this.subscriber.onError(error);
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
/** Prefetches one synchronous item to discover terminal completion without extra demand. */
|
|
252
|
+
lookAheadForSyncTermination() {
|
|
253
|
+
if (!this.syncIterator || this.pendingSyncNext) return;
|
|
254
|
+
try {
|
|
255
|
+
const result = this.syncIterator.next();
|
|
256
|
+
if (this.cancelled || this.terminated) return;
|
|
257
|
+
if (result.done) {
|
|
258
|
+
this.terminated = true;
|
|
259
|
+
this.subscriber.onComplete();
|
|
260
|
+
} else this.pendingSyncNext = result;
|
|
261
|
+
} catch (error) {
|
|
262
|
+
if (!this.cancelled && !this.terminated) {
|
|
263
|
+
this.terminated = true;
|
|
264
|
+
this.subscriber.onError(error);
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
/** Closes active iterators and ignores cleanup failures after cancellation. */
|
|
269
|
+
closeIterators() {
|
|
270
|
+
try {
|
|
271
|
+
this.asyncIterator?.return?.();
|
|
272
|
+
} catch {}
|
|
273
|
+
try {
|
|
274
|
+
this.syncIterator?.return?.();
|
|
275
|
+
} catch {}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
//#endregion
|
|
279
|
+
export { IterableSubscription };
|
|
280
|
+
|
|
281
|
+
//# sourceMappingURL=iterable-subscription.js.map
|