reactor-core-ts 3.2.3 → 3.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/demand.d.ts +4 -0
- package/dist/core/demand.d.ts.map +1 -1
- package/dist/core/demand.js +12 -4
- package/dist/core/demand.js.map +1 -1
- package/dist/internal/iteration-demand.d.ts +18 -0
- package/dist/internal/iteration-demand.d.ts.map +1 -0
- package/dist/internal/iteration-demand.js +34 -0
- package/dist/internal/iteration-demand.js.map +1 -0
- package/dist/internal/publisher-terminal.d.ts +25 -0
- package/dist/internal/publisher-terminal.d.ts.map +1 -0
- package/dist/internal/publisher-terminal.js +128 -0
- package/dist/internal/publisher-terminal.js.map +1 -0
- package/dist/publisher/flux.d.ts.map +1 -1
- package/dist/publisher/flux.js +22 -12
- package/dist/publisher/flux.js.map +1 -1
- package/dist/publisher/mono.d.ts.map +1 -1
- package/dist/publisher/mono.js +2 -1
- package/dist/publisher/mono.js.map +1 -1
- package/dist/publisher/operators/aggregate.d.ts.map +1 -1
- package/dist/publisher/operators/aggregate.js +136 -143
- package/dist/publisher/operators/aggregate.js.map +1 -1
- package/dist/publisher/operators/buffer-lift.d.ts +5 -0
- package/dist/publisher/operators/buffer-lift.d.ts.map +1 -0
- package/dist/publisher/operators/buffer-lift.js +197 -0
- package/dist/publisher/operators/buffer-lift.js.map +1 -0
- package/dist/publisher/operators/compat/flux.d.ts.map +1 -1
- package/dist/publisher/operators/compat/flux.js +86 -35
- package/dist/publisher/operators/compat/flux.js.map +1 -1
- package/dist/publisher/operators/coordination.d.ts.map +1 -1
- package/dist/publisher/operators/coordination.js +3 -4
- package/dist/publisher/operators/coordination.js.map +1 -1
- package/dist/publisher/operators/lifecycle.d.ts.map +1 -1
- package/dist/publisher/operators/lifecycle.js +64 -21
- package/dist/publisher/operators/lifecycle.js.map +1 -1
- package/dist/publisher/operators/lift.d.ts +2 -0
- package/dist/publisher/operators/lift.d.ts.map +1 -1
- package/dist/publisher/operators/lift.js +173 -3
- package/dist/publisher/operators/lift.js.map +1 -1
- package/dist/publisher/operators/selection.d.ts.map +1 -1
- package/dist/publisher/operators/selection.js +3 -2
- package/dist/publisher/operators/selection.js.map +1 -1
- package/dist/publisher/operators/terminal-mono.d.ts +12 -0
- package/dist/publisher/operators/terminal-mono.d.ts.map +1 -0
- package/dist/publisher/operators/terminal-mono.js +244 -0
- package/dist/publisher/operators/terminal-mono.js.map +1 -0
- package/dist/publisher/operators/terminal.d.ts.map +1 -1
- package/dist/publisher/operators/terminal.js +12 -25
- package/dist/publisher/operators/terminal.js.map +1 -1
- package/dist/publisher/operators/time.d.ts.map +1 -1
- package/dist/publisher/operators/time.js +2 -0
- package/dist/publisher/operators/time.js.map +1 -1
- package/dist/subscription/iterable-subscription.d.ts.map +1 -1
- package/dist/subscription/iterable-subscription.js +5 -2
- package/dist/subscription/iterable-subscription.js.map +1 -1
- package/package.json +1 -1
- package/dist/internal/iterable-terminal.d.ts +0 -12
- package/dist/internal/iterable-terminal.d.ts.map +0 -1
- package/dist/internal/iterable-terminal.js +0 -49
- package/dist/internal/iterable-terminal.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.js","names":[],"sources":["../../../src/publisher/operators/time.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {TimeoutError} from \"@/errors/classes.js\";\nimport {AsyncQueue} from \"@/internal/async-queue.js\";\nimport {toAsyncIterator} from \"@/internal/iterable.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {raceIteratorWithTimeout, scheduleDelay, TIMEOUT} from \"@/publisher/helpers.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Time, scheduling and timeout operators added to Flux. */\n interface Flux<T> {\n /** Delays each source value on the provided scheduler before emitting it. */\n delayElements(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Fails or switches to a fallback when the source does not signal in time. */\n timeout(timeout: DurationInput, fallback?: PublisherInput<T>, scheduler?: Scheduler): Flux<T>;\n\n /** Reschedules value delivery on the provided scheduler. */\n publishOn(scheduler: Scheduler): Flux<T>;\n\n /** Schedules subscription work on the provided scheduler. */\n subscribeOn(scheduler: Scheduler): Flux<T>;\n\n /** Emits each value together with the scheduler timestamp. */\n timestamp(scheduler?: Scheduler): Flux<readonly [number, T]>;\n\n /** Emits each value together with elapsed scheduler time since the previous value. */\n elapsed(scheduler?: Scheduler): Flux<readonly [number, T]>;\n }\n}\n\nFlux.prototype.delayElements = function delayElements<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await scheduleDelay(scheduler, delay, signal);\n yield value;\n }\n });\n};\n\nFlux.prototype.timeout = function timeout<T>(\n this: Flux<T>,\n timeout: DurationInput,\n fallback?: PublisherInput<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const controller = new AbortController();\n const abort = () => controller.abort();\n signal.addEventListener(\"abort\", abort, {once: true});\n const iterator = toAsyncIterator(source.iterate(controller.signal, context));\n try {\n while (!signal.aborted) {\n const result = await raceIteratorWithTimeout(iterator, timeout, scheduler, signal);\n if (result === TIMEOUT) {\n controller.abort();\n if (fallback) {\n for await (const value of Flux.from(fallback).iterate(signal, context)) {\n yield value;\n }\n return;\n }\n throw new TimeoutError();\n }\n if (result.done) {\n return;\n }\n yield result.value;\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n controller.abort();\n void iterator.return?.();\n }\n });\n};\n\nFlux.prototype.publishOn = function publishOn<T>(this: Flux<T>, scheduler: Scheduler): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await scheduleDelay(scheduler, 0, signal);\n yield value;\n }\n });\n};\n\nFlux.prototype.subscribeOn = function subscribeOn<T>(this: Flux<T>, scheduler: Scheduler): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n const queue = new AsyncQueue<T>(signal);\n const disposable = scheduler.schedule(() => {\n void (async () => {\n try {\n for await (const value of source.iterate(signal, context)) {\n queue.push(value);\n }\n queue.complete();\n } catch (error) {\n queue.error(error);\n }\n })();\n });\n signal.addEventListener(\"abort\", () => disposable.dispose(), {once: true});\n return queue;\n });\n};\n\nFlux.prototype.timestamp = function timestamp<T>(\n this: Flux<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<readonly [number, T]> {\n return this.map(value => [scheduler.now(), value] as const);\n};\n\nFlux.prototype.elapsed = function elapsed<T>(\n this: Flux<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<readonly [number, T]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let last = scheduler.now();\n for await (const value of source.iterate(signal, context)) {\n const now = scheduler.now();\n yield [now - last, value] as const;\n last = now;\n }\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.js","names":[],"sources":["../../../src/publisher/operators/time.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Flux, Mono and operator implementation modules.\n */\nimport {TimeoutError} from \"@/errors/classes.js\";\nimport {AsyncQueue} from \"@/internal/async-queue.js\";\nimport {toAsyncIterator} from \"@/internal/iterable.js\";\nimport {inheritIterationDemand} from \"@/internal/iteration-demand.js\";\nimport {Flux} from \"@/publisher/flux.js\";\nimport {raceIteratorWithTimeout, scheduleDelay, TIMEOUT} from \"@/publisher/helpers.js\";\nimport type {PublisherInput} from \"@/publisher/types.js\";\nimport {Schedulers} from \"@/schedulers/schedulers.js\";\nimport type {DurationInput, Scheduler} from \"@/schedulers/types.js\";\n\ndeclare module \"@/publisher/flux.js\" {\n /** Time, scheduling and timeout operators added to Flux. */\n interface Flux<T> {\n /** Delays each source value on the provided scheduler before emitting it. */\n delayElements(delay: DurationInput, scheduler?: Scheduler): Flux<T>;\n\n /** Fails or switches to a fallback when the source does not signal in time. */\n timeout(timeout: DurationInput, fallback?: PublisherInput<T>, scheduler?: Scheduler): Flux<T>;\n\n /** Reschedules value delivery on the provided scheduler. */\n publishOn(scheduler: Scheduler): Flux<T>;\n\n /** Schedules subscription work on the provided scheduler. */\n subscribeOn(scheduler: Scheduler): Flux<T>;\n\n /** Emits each value together with the scheduler timestamp. */\n timestamp(scheduler?: Scheduler): Flux<readonly [number, T]>;\n\n /** Emits each value together with elapsed scheduler time since the previous value. */\n elapsed(scheduler?: Scheduler): Flux<readonly [number, T]>;\n }\n}\n\nFlux.prototype.delayElements = function delayElements<T>(\n this: Flux<T>,\n delay: DurationInput,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await scheduleDelay(scheduler, delay, signal);\n yield value;\n }\n });\n};\n\nFlux.prototype.timeout = function timeout<T>(\n this: Flux<T>,\n timeout: DurationInput,\n fallback?: PublisherInput<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n const controller = new AbortController();\n inheritIterationDemand(signal, controller.signal);\n const abort = () => controller.abort();\n signal.addEventListener(\"abort\", abort, {once: true});\n const iterator = toAsyncIterator(source.iterate(controller.signal, context));\n try {\n while (!signal.aborted) {\n const result = await raceIteratorWithTimeout(iterator, timeout, scheduler, signal);\n if (result === TIMEOUT) {\n controller.abort();\n if (fallback) {\n for await (const value of Flux.from(fallback).iterate(signal, context)) {\n yield value;\n }\n return;\n }\n throw new TimeoutError();\n }\n if (result.done) {\n return;\n }\n yield result.value;\n }\n } finally {\n signal.removeEventListener(\"abort\", abort);\n controller.abort();\n void iterator.return?.();\n }\n });\n};\n\nFlux.prototype.publishOn = function publishOn<T>(this: Flux<T>, scheduler: Scheduler): Flux<T> {\n const source = this;\n return new Flux(async function* (signal, context) {\n for await (const value of source.iterate(signal, context)) {\n await scheduleDelay(scheduler, 0, signal);\n yield value;\n }\n });\n};\n\nFlux.prototype.subscribeOn = function subscribeOn<T>(this: Flux<T>, scheduler: Scheduler): Flux<T> {\n const source = this;\n return new Flux((signal, context) => {\n const queue = new AsyncQueue<T>(signal);\n const disposable = scheduler.schedule(() => {\n void (async () => {\n try {\n for await (const value of source.iterate(signal, context)) {\n queue.push(value);\n }\n queue.complete();\n } catch (error) {\n queue.error(error);\n }\n })();\n });\n signal.addEventListener(\"abort\", () => disposable.dispose(), {once: true});\n return queue;\n });\n};\n\nFlux.prototype.timestamp = function timestamp<T>(\n this: Flux<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<readonly [number, T]> {\n return this.map(value => [scheduler.now(), value] as const);\n};\n\nFlux.prototype.elapsed = function elapsed<T>(\n this: Flux<T>,\n scheduler: Scheduler = Schedulers.timeout()\n): Flux<readonly [number, T]> {\n const source = this;\n return new Flux(async function* (signal, context) {\n let last = scheduler.now();\n for await (const value of source.iterate(signal, context)) {\n const now = scheduler.now();\n yield [now - last, value] as const;\n last = now;\n }\n });\n};\n"],"mappings":";;;;;;;;;;;;AAqCA,KAAK,UAAU,gBAAgB,SAAS,cAEpC,OACA,YAAuB,WAAW,QAAQ,GACnC;CACP,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;GACvD,MAAM,cAAc,WAAW,OAAO,MAAM;GAC5C,MAAM;EACV;CACJ,CAAC;AACL;AAEA,KAAK,UAAU,UAAU,SAAS,QAE9B,SACA,UACA,YAAuB,WAAW,QAAQ,GACnC;CACP,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,MAAM,aAAa,IAAI,gBAAgB;EACvC,uBAAuB,QAAQ,WAAW,MAAM;EAChD,MA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,EAAC,MAAM,KAAI,CAAC;EACzE,OAAO;CACX,CAAC;AACL;AAEA,KAAK,UAAU,YAAY,SAAS,UAEhC,YAAuB,WAAW,QAAQ,GAChB;CAC1B,OAAO,KAAK,KAAI,UAAS,CAAC,UAAU,IAAI,GAAG,KAAK,CAAU;AAC9D;AAEA,KAAK,UAAU,UAAU,SAAS,QAE9B,YAAuB,WAAW,QAAQ,GAChB;CAC1B,MAAM,SAAS;CACf,OAAO,IAAI,KAAK,iBAAiB,QAAQ,SAAS;EAC9C,IAAI,OAAO,UAAU,IAAI;EACzB,WAAW,MAAM,SAAS,OAAO,QAAQ,QAAQ,OAAO,GAAG;GACvD,MAAM,MAAM,UAAU,IAAI;GAC1B,MAAM,CAAC,MAAM,MAAM,KAAK;GACxB,OAAO;EACX;CACJ,CAAC;AACL"}
|
|
@@ -1 +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;
|
|
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;AAIlD,OAAO,KAAK,EAAC,IAAI,EAAC,MAAM,qBAAqB,CAAC;AAC9C,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,8BAA8B,CAAC;AAC7D,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,gCAAgC,CAAC;AAEjE,oFAAoF;AACpF,qBAAa,oBAAoB,CAAC,CAAC,CAAE,YAAW,YAAY;IACxD,kEAAkE;IAClE,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAyB;IACpD,2DAA2D;IAC3D,OAAO,CAAC,aAAa,CAA+B;IACpD,iEAAiE;IACjE,OAAO,CAAC,YAAY,CAA0B;IAC9C,6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OAAO,CAAC,cAAc;CAYzB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _defineProperty from "../_virtual/_@oxc-project_runtime@0.139.0/helpers/esm/defineProperty.js";
|
|
2
2
|
import { doneResult, isAsyncIterable, resolvedDoneResult } from "../internal/iterable.js";
|
|
3
|
-
import { addCap, normalizeRequest } from "../core/demand.js";
|
|
3
|
+
import { UNBOUNDED_DEMAND, addCap, normalizeRequest } from "../core/demand.js";
|
|
4
|
+
import { applyIterationDemandHint, markUnboundedIteration } from "../internal/iteration-demand.js";
|
|
4
5
|
import { scheduleMicrotask } from "../internal/microtask.js";
|
|
5
6
|
//#region src/subscription/iterable-subscription.ts
|
|
6
7
|
/**
|
|
@@ -104,6 +105,7 @@ var IterableSubscription = class {
|
|
|
104
105
|
this.flux = flux;
|
|
105
106
|
this.subscriber = subscriber;
|
|
106
107
|
this.context = context;
|
|
108
|
+
applyIterationDemandHint(this.controller.signal, subscriber);
|
|
107
109
|
}
|
|
108
110
|
/** Starts source assembly without pulling any values from it. */
|
|
109
111
|
start() {
|
|
@@ -136,6 +138,7 @@ var IterableSubscription = class {
|
|
|
136
138
|
this.subscriber.onError(error);
|
|
137
139
|
return;
|
|
138
140
|
}
|
|
141
|
+
if (request === UNBOUNDED_DEMAND) markUnboundedIteration(this.controller.signal);
|
|
139
142
|
this.requested = addCap(this.requested, request);
|
|
140
143
|
if (this.hasStartFailure) {
|
|
141
144
|
this.deliverStartFailure();
|
|
@@ -197,7 +200,7 @@ var IterableSubscription = class {
|
|
|
197
200
|
this.subscriber.onComplete();
|
|
198
201
|
return true;
|
|
199
202
|
}
|
|
200
|
-
if (this.requested !==
|
|
203
|
+
if (this.requested !== UNBOUNDED_DEMAND) this.requested -= 1;
|
|
201
204
|
try {
|
|
202
205
|
this.subscriber.onNext(result.value);
|
|
203
206
|
} catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-subscription.js","names":[],"sources":["../../src/subscription/iterable-subscription.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactive Streams subscription and subscriber contracts.\n */\nimport {addCap, normalizeRequest} from \"@/core/demand.js\";\nimport type {Context} from \"@/context/context.js\";\nimport {doneResult, isAsyncIterable, resolvedDoneResult} from \"@/internal/iterable.js\";\nimport {scheduleMicrotask} from \"@/internal/microtask.js\";\nimport type {Flux} from \"@/publisher/flux.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Subscription implementation that drains a Flux only when demand is requested. */\nexport class IterableSubscription<T> implements Subscription {\n /** Abort controller used to cancel the active source iterator. */\n private readonly controller = new AbortController();\n /** Lazily created async iterator over the backing Flux. */\n private asyncIterator: AsyncIterator<T> | undefined;\n /** Lazily created synchronous iterator over the backing Flux. */\n private syncIterator: Iterator<T> | undefined;\n /** Tracks whether the source iterator has been assembled. */\n private started = false;\n /** Stores a synchronous source assembly failure until it can be signalled. */\n private startFailure: unknown;\n /** Tracks whether source assembly failed synchronously. */\n private hasStartFailure = false;\n /** Prefetched async result used to detect completion with zero demand. */\n private pendingAsyncNext: Promise<IteratorResult<T>> | undefined;\n /** Prefetched sync result used to detect completion with zero demand. */\n private pendingSyncNext: IteratorResult<T> | undefined;\n /** Outstanding downstream demand. */\n private requested = 0;\n /** Guards against concurrent drain loops. */\n private draining = false;\n /** Tracks downstream cancellation. */\n private cancelled = false;\n /** Tracks terminal completion or failure delivery. */\n private terminated = false;\n /** Source Flux drained by this subscription. */\n private readonly flux: Flux<T>;\n /** Downstream subscriber receiving signals. */\n private readonly subscriber: Subscriber<T>;\n /** Context used for the source iteration. */\n private readonly context: Context;\n\n /** Creates a subscription for the provided Flux and subscriber. */\n public constructor(flux: Flux<T>, subscriber: Subscriber<T>, context: Context) {\n this.flux = flux;\n this.subscriber = subscriber;\n this.context = context;\n }\n\n /** Starts source assembly without pulling any values from it. */\n public start(): void {\n if (this.started || this.cancelled || this.terminated) {\n return;\n }\n this.started = true;\n try {\n const source = this.flux.iterate(this.controller.signal, this.context);\n if (isAsyncIterable<T>(source)) {\n this.asyncIterator = source[Symbol.asyncIterator]();\n } else {\n this.syncIterator = source[Symbol.iterator]();\n }\n } catch (error) {\n this.startFailure = error;\n this.hasStartFailure = true;\n }\n }\n\n /** Delivers a synchronous source assembly failure after `onSubscribe`. */\n public deliverStartFailure(): void {\n if (!this.hasStartFailure || this.cancelled || this.terminated) {\n return;\n }\n this.hasStartFailure = false;\n this.terminated = true;\n this.subscriber.onError(this.startFailure);\n }\n\n /** Requests more values from the backing iterator. */\n public request(n: number): void {\n if (this.cancelled || this.terminated) {\n return;\n }\n let request: number;\n try {\n request = normalizeRequest(n);\n } catch (error) {\n this.cancel();\n this.subscriber.onError(error);\n return;\n }\n this.requested = addCap(this.requested, request);\n if (this.hasStartFailure) {\n this.deliverStartFailure();\n return;\n }\n void this.drain();\n }\n\n /** Cancels iteration and closes upstream resources. */\n public cancel(): void {\n if (this.cancelled || this.terminated) {\n return;\n }\n this.cancelled = true;\n this.controller.abort();\n this.closeIterators();\n }\n\n /** Drains the source while there is outstanding demand. */\n private async drain(): Promise<void> {\n if (this.draining) {\n return;\n }\n this.draining = true;\n try {\n this.start();\n if (this.hasStartFailure) {\n this.deliverStartFailure();\n return;\n }\n if (this.syncIterator) {\n this.drainSync();\n return;\n }\n while (!this.cancelled && !this.terminated && this.requested > 0) {\n const result = await this.nextAsyncResult();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (this.deliverResult(result)) {\n return;\n }\n }\n } catch (error) {\n if (!this.cancelled && !this.terminated) {\n this.terminated = true;\n this.subscriber.onError(error);\n }\n } finally {\n this.draining = false;\n if (!this.cancelled && !this.terminated && this.requested > 0) {\n scheduleMicrotask(() => {\n void this.drain();\n });\n } else if (!this.cancelled && !this.terminated && this.requested === 0) {\n this.lookAheadForTermination();\n }\n }\n }\n\n /** Drains a synchronous source without per-item promise allocation. */\n private drainSync(): void {\n while (!this.cancelled && !this.terminated && this.requested > 0) {\n const result = this.nextSyncResult();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (this.deliverResult(result)) {\n return;\n }\n }\n }\n\n /** Returns true after delivering a terminal result. */\n private deliverResult(result: IteratorResult<T>): boolean {\n if (result.done) {\n this.terminated = true;\n this.subscriber.onComplete();\n return true;\n }\n if (this.requested !== Number.POSITIVE_INFINITY) {\n this.requested -= 1;\n }\n try {\n this.subscriber.onNext(result.value);\n } catch (error) {\n this.cancel();\n this.subscriber.onError(error);\n return true;\n }\n return false;\n }\n\n /** Returns the pending prefetched async result or asks the async iterator for the next item. */\n private nextAsyncResult(): Promise<IteratorResult<T>> {\n if (this.pendingAsyncNext) {\n const pending = this.pendingAsyncNext;\n this.pendingAsyncNext = undefined;\n return pending;\n }\n return this.asyncIterator?.next() ?? resolvedDoneResult<T>();\n }\n\n /** Returns the pending prefetched sync result or asks the sync iterator for the next item. */\n private nextSyncResult(): IteratorResult<T> {\n if (this.pendingSyncNext) {\n const pending = this.pendingSyncNext;\n this.pendingSyncNext = undefined;\n return pending;\n }\n return this.syncIterator?.next() ?? doneResult<T>();\n }\n\n /** Prefetches one item to discover terminal completion without extra demand. */\n private lookAheadForTermination(): void {\n if (this.syncIterator) {\n this.lookAheadForSyncTermination();\n return;\n }\n if (!this.asyncIterator || this.pendingAsyncNext) {\n return;\n }\n const pending = this.asyncIterator.next();\n this.pendingAsyncNext = pending;\n pending.then(\n result => {\n if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) {\n return;\n }\n if (result.done) {\n this.pendingAsyncNext = undefined;\n this.terminated = true;\n this.subscriber.onComplete();\n }\n },\n error => {\n if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) {\n return;\n }\n this.pendingAsyncNext = undefined;\n this.terminated = true;\n this.subscriber.onError(error);\n }\n );\n }\n\n /** Prefetches one synchronous item to discover terminal completion without extra demand. */\n private lookAheadForSyncTermination(): void {\n if (!this.syncIterator || this.pendingSyncNext) {\n return;\n }\n try {\n const result = this.syncIterator.next();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (result.done) {\n this.terminated = true;\n this.subscriber.onComplete();\n } else {\n this.pendingSyncNext = result;\n }\n } catch (error) {\n if (!this.cancelled && !this.terminated) {\n this.terminated = true;\n this.subscriber.onError(error);\n }\n }\n }\n\n /** Closes active iterators and ignores cleanup failures after cancellation. */\n private closeIterators(): void {\n try {\n void this.asyncIterator?.return?.();\n } catch {\n // cancellation best-effort cleanup\n }\n try {\n this.syncIterator?.return?.();\n } catch {\n // cancellation best-effort cleanup\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAaA,IAAa,uBAAb,MAA6D;;CAiCzD,YAAmB,MAAe,YAA2B,SAAkB;;;;GA/B/E;GAA8B,IAAI,gBAAgB;;;;;GAElD;;;;;;GAEA;;;;;;GAEA;GAAkB;;;;;GAElB;;;;;;GAEA;GAA0B;;;;;GAE1B;;;;;;GAEA;;;;;;GAEA;GAAoB;;;;;GAEpB;GAAmB;;;;;GAEnB;GAAoB;;;;;GAEpB;GAAqB;;;;;GAErB;;;;;;GAEA;;;;;;GAEA;;;EAII,KAAK,OAAO;EACZ,KAAK,aAAa;EAClB,KAAK,UAAU;CACnB;;CAGA,QAAqB;EACjB,IAAI,KAAK,WAAW,KAAK,aAAa,KAAK,YACvC;EAEJ,KAAK,UAAU;EACf,IAAI;GACA,MAAM,SAAS,KAAK,KAAK,QAAQ,KAAK,WAAW,QAAQ,KAAK,OAAO;GACrE,IAAI,gBAAmB,MAAM,GACzB,KAAK,gBAAgB,OAAO,OAAO,cAAc,CAAC;QAElD,KAAK,eAAe,OAAO,OAAO,SAAS,CAAC;EAEpD,SAAS,OAAO;GACZ,KAAK,eAAe;GACpB,KAAK,kBAAkB;EAC3B;CACJ;;CAGA,sBAAmC;EAC/B,IAAI,CAAC,KAAK,mBAAmB,KAAK,aAAa,KAAK,YAChD;EAEJ,KAAK,kBAAkB;EACvB,KAAK,aAAa;EAClB,KAAK,WAAW,QAAQ,KAAK,YAAY;CAC7C;;CA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KAAK;EACjC,CACJ;CACJ;;CAGA,8BAA4C;EACxC,IAAI,CAAC,KAAK,gBAAgB,KAAK,iBAC3B;EAEJ,IAAI;GACA,MAAM,SAAS,KAAK,aAAa,KAAK;GACtC,IAAI,KAAK,aAAa,KAAK,YACvB;GAEJ,IAAI,OAAO,MAAM;IACb,KAAK,aAAa;IAClB,KAAK,WAAW,WAAW;GAC/B,OACI,KAAK,kBAAkB;EAE/B,SAAS,OAAO;GACZ,IAAI,CAAC,KAAK,aAAa,CAAC,KAAK,YAAY;IACrC,KAAK,aAAa;IAClB,KAAK,WAAW,QAAQ,KAAK;GACjC;EACJ;CACJ;;CAGA,iBAA+B;EAC3B,IAAI;GACA,AAAK,KAAK,eAAe,SAAS;EACtC,QAAQ,CAER;EACA,IAAI;GACA,KAAK,cAAc,SAAS;EAChC,QAAQ,CAER;CACJ;AACJ"}
|
|
1
|
+
{"version":3,"file":"iterable-subscription.js","names":[],"sources":["../../src/subscription/iterable-subscription.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Reactive Streams subscription and subscriber contracts.\n */\nimport {addCap, normalizeRequest, UNBOUNDED_DEMAND} from \"@/core/demand.js\";\nimport type {Context} from \"@/context/context.js\";\nimport {doneResult, isAsyncIterable, resolvedDoneResult} from \"@/internal/iterable.js\";\nimport {applyIterationDemandHint, markUnboundedIteration} from \"@/internal/iteration-demand.js\";\nimport {scheduleMicrotask} from \"@/internal/microtask.js\";\nimport type {Flux} from \"@/publisher/flux.js\";\nimport type {Subscriber} from \"@/subscription/subscriber.js\";\nimport type {Subscription} from \"@/subscription/subscription.js\";\n\n/** Subscription implementation that drains a Flux only when demand is requested. */\nexport class IterableSubscription<T> implements Subscription {\n /** Abort controller used to cancel the active source iterator. */\n private readonly controller = new AbortController();\n /** Lazily created async iterator over the backing Flux. */\n private asyncIterator: AsyncIterator<T> | undefined;\n /** Lazily created synchronous iterator over the backing Flux. */\n private syncIterator: Iterator<T> | undefined;\n /** Tracks whether the source iterator has been assembled. */\n private started = false;\n /** Stores a synchronous source assembly failure until it can be signalled. */\n private startFailure: unknown;\n /** Tracks whether source assembly failed synchronously. */\n private hasStartFailure = false;\n /** Prefetched async result used to detect completion with zero demand. */\n private pendingAsyncNext: Promise<IteratorResult<T>> | undefined;\n /** Prefetched sync result used to detect completion with zero demand. */\n private pendingSyncNext: IteratorResult<T> | undefined;\n /** Outstanding downstream demand. */\n private requested = 0;\n /** Guards against concurrent drain loops. */\n private draining = false;\n /** Tracks downstream cancellation. */\n private cancelled = false;\n /** Tracks terminal completion or failure delivery. */\n private terminated = false;\n /** Source Flux drained by this subscription. */\n private readonly flux: Flux<T>;\n /** Downstream subscriber receiving signals. */\n private readonly subscriber: Subscriber<T>;\n /** Context used for the source iteration. */\n private readonly context: Context;\n\n /** Creates a subscription for the provided Flux and subscriber. */\n public constructor(flux: Flux<T>, subscriber: Subscriber<T>, context: Context) {\n this.flux = flux;\n this.subscriber = subscriber;\n this.context = context;\n applyIterationDemandHint(this.controller.signal, subscriber);\n }\n\n /** Starts source assembly without pulling any values from it. */\n public start(): void {\n if (this.started || this.cancelled || this.terminated) {\n return;\n }\n this.started = true;\n try {\n const source = this.flux.iterate(this.controller.signal, this.context);\n if (isAsyncIterable<T>(source)) {\n this.asyncIterator = source[Symbol.asyncIterator]();\n } else {\n this.syncIterator = source[Symbol.iterator]();\n }\n } catch (error) {\n this.startFailure = error;\n this.hasStartFailure = true;\n }\n }\n\n /** Delivers a synchronous source assembly failure after `onSubscribe`. */\n public deliverStartFailure(): void {\n if (!this.hasStartFailure || this.cancelled || this.terminated) {\n return;\n }\n this.hasStartFailure = false;\n this.terminated = true;\n this.subscriber.onError(this.startFailure);\n }\n\n /** Requests more values from the backing iterator. */\n public request(n: number): void {\n if (this.cancelled || this.terminated) {\n return;\n }\n let request: number;\n try {\n request = normalizeRequest(n);\n } catch (error) {\n this.cancel();\n this.subscriber.onError(error);\n return;\n }\n if (request === UNBOUNDED_DEMAND) {\n markUnboundedIteration(this.controller.signal);\n }\n this.requested = addCap(this.requested, request);\n if (this.hasStartFailure) {\n this.deliverStartFailure();\n return;\n }\n void this.drain();\n }\n\n /** Cancels iteration and closes upstream resources. */\n public cancel(): void {\n if (this.cancelled || this.terminated) {\n return;\n }\n this.cancelled = true;\n this.controller.abort();\n this.closeIterators();\n }\n\n /** Drains the source while there is outstanding demand. */\n private async drain(): Promise<void> {\n if (this.draining) {\n return;\n }\n this.draining = true;\n try {\n this.start();\n if (this.hasStartFailure) {\n this.deliverStartFailure();\n return;\n }\n if (this.syncIterator) {\n this.drainSync();\n return;\n }\n while (!this.cancelled && !this.terminated && this.requested > 0) {\n const result = await this.nextAsyncResult();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (this.deliverResult(result)) {\n return;\n }\n }\n } catch (error) {\n if (!this.cancelled && !this.terminated) {\n this.terminated = true;\n this.subscriber.onError(error);\n }\n } finally {\n this.draining = false;\n if (!this.cancelled && !this.terminated && this.requested > 0) {\n scheduleMicrotask(() => {\n void this.drain();\n });\n } else if (!this.cancelled && !this.terminated && this.requested === 0) {\n this.lookAheadForTermination();\n }\n }\n }\n\n /** Drains a synchronous source without per-item promise allocation. */\n private drainSync(): void {\n while (!this.cancelled && !this.terminated && this.requested > 0) {\n const result = this.nextSyncResult();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (this.deliverResult(result)) {\n return;\n }\n }\n }\n\n /** Returns true after delivering a terminal result. */\n private deliverResult(result: IteratorResult<T>): boolean {\n if (result.done) {\n this.terminated = true;\n this.subscriber.onComplete();\n return true;\n }\n if (this.requested !== UNBOUNDED_DEMAND) {\n this.requested -= 1;\n }\n try {\n this.subscriber.onNext(result.value);\n } catch (error) {\n this.cancel();\n this.subscriber.onError(error);\n return true;\n }\n return false;\n }\n\n /** Returns the pending prefetched async result or asks the async iterator for the next item. */\n private nextAsyncResult(): Promise<IteratorResult<T>> {\n if (this.pendingAsyncNext) {\n const pending = this.pendingAsyncNext;\n this.pendingAsyncNext = undefined;\n return pending;\n }\n return this.asyncIterator?.next() ?? resolvedDoneResult<T>();\n }\n\n /** Returns the pending prefetched sync result or asks the sync iterator for the next item. */\n private nextSyncResult(): IteratorResult<T> {\n if (this.pendingSyncNext) {\n const pending = this.pendingSyncNext;\n this.pendingSyncNext = undefined;\n return pending;\n }\n return this.syncIterator?.next() ?? doneResult<T>();\n }\n\n /** Prefetches one item to discover terminal completion without extra demand. */\n private lookAheadForTermination(): void {\n if (this.syncIterator) {\n this.lookAheadForSyncTermination();\n return;\n }\n if (!this.asyncIterator || this.pendingAsyncNext) {\n return;\n }\n const pending = this.asyncIterator.next();\n this.pendingAsyncNext = pending;\n pending.then(\n result => {\n if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) {\n return;\n }\n if (result.done) {\n this.pendingAsyncNext = undefined;\n this.terminated = true;\n this.subscriber.onComplete();\n }\n },\n error => {\n if (this.pendingAsyncNext !== pending || this.cancelled || this.terminated) {\n return;\n }\n this.pendingAsyncNext = undefined;\n this.terminated = true;\n this.subscriber.onError(error);\n }\n );\n }\n\n /** Prefetches one synchronous item to discover terminal completion without extra demand. */\n private lookAheadForSyncTermination(): void {\n if (!this.syncIterator || this.pendingSyncNext) {\n return;\n }\n try {\n const result = this.syncIterator.next();\n if (this.cancelled || this.terminated) {\n return;\n }\n if (result.done) {\n this.terminated = true;\n this.subscriber.onComplete();\n } else {\n this.pendingSyncNext = result;\n }\n } catch (error) {\n if (!this.cancelled && !this.terminated) {\n this.terminated = true;\n this.subscriber.onError(error);\n }\n }\n }\n\n /** Closes active iterators and ignores cleanup failures after cancellation. */\n private closeIterators(): void {\n try {\n void this.asyncIterator?.return?.();\n } catch {\n // cancellation best-effort cleanup\n }\n try {\n this.syncIterator?.return?.();\n } catch {\n // cancellation best-effort cleanup\n }\n }\n}\n"],"mappings":";;;;;;;;;;;AAcA,IAAa,uBAAb,MAA6D;;CAiCzD,YAAmB,MAAe,YAA2B,SAAkB;;;;GA/B/E;GAA8B,IAAI,gBAAgB;;;;;GAElD;;;;;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ACJ;CACJ;;CAGA,iBAA+B;EAC3B,IAAI;GACA,AAAK,KAAK,eAAe,SAAS;EACtC,QAAQ,CAER;EACA,IAAI;GACA,KAAK,cAAc,SAAS;EAChC,QAAQ,CAER;CACJ;AACJ"}
|
package/package.json
CHANGED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* Internal iterable terminal helpers.
|
|
4
|
-
*/
|
|
5
|
-
import { type AnyIterable } from "./iterable.js";
|
|
6
|
-
/** Collects an iterable into an array, using a synchronous loop when possible. */
|
|
7
|
-
export declare function collectIterable<T>(source: AnyIterable<T>): T[] | Promise<T[]>;
|
|
8
|
-
/** Returns the last value from an iterable, or undefined when it is empty. */
|
|
9
|
-
export declare function lastIterableValue<T>(source: AnyIterable<T>): T | undefined | Promise<T | undefined>;
|
|
10
|
-
/** Counts iterable values, using a synchronous loop when possible. */
|
|
11
|
-
export declare function countIterable<T>(source: AnyIterable<T>): number | Promise<number>;
|
|
12
|
-
//# sourceMappingURL=iterable-terminal.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-terminal.d.ts","sourceRoot":"","sources":["../../src/internal/iterable-terminal.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,KAAK,WAAW,EAAkB,MAAM,wBAAwB,CAAC;AAEzE,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC,CAS7E;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,SAAS,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CASnG;AAED,sEAAsE;AACtE,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CASjF"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { isAsyncIterable } from "./iterable.js";
|
|
2
|
-
//#region src/internal/iterable-terminal.ts
|
|
3
|
-
/**
|
|
4
|
-
* @packageDocumentation
|
|
5
|
-
* Internal iterable terminal helpers.
|
|
6
|
-
*/
|
|
7
|
-
/** Collects an iterable into an array, using a synchronous loop when possible. */
|
|
8
|
-
function collectIterable(source) {
|
|
9
|
-
if (isAsyncIterable(source)) return collectAsync(source);
|
|
10
|
-
const values = [];
|
|
11
|
-
for (const value of source) values.push(value);
|
|
12
|
-
return values;
|
|
13
|
-
}
|
|
14
|
-
/** Returns the last value from an iterable, or undefined when it is empty. */
|
|
15
|
-
function lastIterableValue(source) {
|
|
16
|
-
if (isAsyncIterable(source)) return lastAsync(source);
|
|
17
|
-
let last;
|
|
18
|
-
for (const value of source) last = value;
|
|
19
|
-
return last;
|
|
20
|
-
}
|
|
21
|
-
/** Counts iterable values, using a synchronous loop when possible. */
|
|
22
|
-
function countIterable(source) {
|
|
23
|
-
if (isAsyncIterable(source)) return countAsync(source);
|
|
24
|
-
let count = 0;
|
|
25
|
-
for (const _ of source) count += 1;
|
|
26
|
-
return count;
|
|
27
|
-
}
|
|
28
|
-
/** Collects an async iterable into an array. */
|
|
29
|
-
async function collectAsync(source) {
|
|
30
|
-
const values = [];
|
|
31
|
-
for await (const value of source) values.push(value);
|
|
32
|
-
return values;
|
|
33
|
-
}
|
|
34
|
-
/** Returns the last async iterable value, or undefined when empty. */
|
|
35
|
-
async function lastAsync(source) {
|
|
36
|
-
let last;
|
|
37
|
-
for await (const value of source) last = value;
|
|
38
|
-
return last;
|
|
39
|
-
}
|
|
40
|
-
/** Counts async iterable values. */
|
|
41
|
-
async function countAsync(source) {
|
|
42
|
-
let count = 0;
|
|
43
|
-
for await (const _ of source) count += 1;
|
|
44
|
-
return count;
|
|
45
|
-
}
|
|
46
|
-
//#endregion
|
|
47
|
-
export { collectIterable, countIterable, lastIterableValue };
|
|
48
|
-
|
|
49
|
-
//# sourceMappingURL=iterable-terminal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"iterable-terminal.js","names":[],"sources":["../../src/internal/iterable-terminal.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * Internal iterable terminal helpers.\n */\nimport {type AnyIterable, isAsyncIterable} from \"@/internal/iterable.js\";\n\n/** Collects an iterable into an array, using a synchronous loop when possible. */\nexport function collectIterable<T>(source: AnyIterable<T>): T[] | Promise<T[]> {\n if (isAsyncIterable<T>(source)) {\n return collectAsync(source);\n }\n const values: T[] = [];\n for (const value of source) {\n values.push(value);\n }\n return values;\n}\n\n/** Returns the last value from an iterable, or undefined when it is empty. */\nexport function lastIterableValue<T>(source: AnyIterable<T>): T | undefined | Promise<T | undefined> {\n if (isAsyncIterable<T>(source)) {\n return lastAsync(source);\n }\n let last: T | undefined;\n for (const value of source) {\n last = value;\n }\n return last;\n}\n\n/** Counts iterable values, using a synchronous loop when possible. */\nexport function countIterable<T>(source: AnyIterable<T>): number | Promise<number> {\n if (isAsyncIterable<T>(source)) {\n return countAsync(source);\n }\n let count = 0;\n for (const _ of source) {\n count += 1;\n }\n return count;\n}\n\n/** Collects an async iterable into an array. */\nasync function collectAsync<T>(source: AsyncIterable<T>): Promise<T[]> {\n const values: T[] = [];\n for await (const value of source) {\n values.push(value);\n }\n return values;\n}\n\n/** Returns the last async iterable value, or undefined when empty. */\nasync function lastAsync<T>(source: AsyncIterable<T>): Promise<T | undefined> {\n let last: T | undefined;\n for await (const value of source) {\n last = value;\n }\n return last;\n}\n\n/** Counts async iterable values. */\nasync function countAsync<T>(source: AsyncIterable<T>): Promise<number> {\n let count = 0;\n for await (const _ of source) {\n count += 1;\n }\n return count;\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,gBAAmB,QAA4C;CAC3E,IAAI,gBAAmB,MAAM,GACzB,OAAO,aAAa,MAAM;CAE9B,MAAM,SAAc,CAAC;CACrB,KAAK,MAAM,SAAS,QAChB,OAAO,KAAK,KAAK;CAErB,OAAO;AACX;;AAGA,SAAgB,kBAAqB,QAAgE;CACjG,IAAI,gBAAmB,MAAM,GACzB,OAAO,UAAU,MAAM;CAE3B,IAAI;CACJ,KAAK,MAAM,SAAS,QAChB,OAAO;CAEX,OAAO;AACX;;AAGA,SAAgB,cAAiB,QAAkD;CAC/E,IAAI,gBAAmB,MAAM,GACzB,OAAO,WAAW,MAAM;CAE5B,IAAI,QAAQ;CACZ,KAAK,MAAM,KAAK,QACZ,SAAS;CAEb,OAAO;AACX;;AAGA,eAAe,aAAgB,QAAwC;CACnE,MAAM,SAAc,CAAC;CACrB,WAAW,MAAM,SAAS,QACtB,OAAO,KAAK,KAAK;CAErB,OAAO;AACX;;AAGA,eAAe,UAAa,QAAkD;CAC1E,IAAI;CACJ,WAAW,MAAM,SAAS,QACtB,OAAO;CAEX,OAAO;AACX;;AAGA,eAAe,WAAc,QAA2C;CACpE,IAAI,QAAQ;CACZ,WAAW,MAAM,KAAK,QAClB,SAAS;CAEb,OAAO;AACX"}
|