reactor-core-ts 2.1.1 → 2.1.3
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 +38 -1
- package/dist/index.d.mts +66 -3
- package/dist/index.d.ts +66 -3
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -336,10 +336,20 @@ Flux.just('a', 'b', 'c')
|
|
|
336
336
|
| Method | Description |
|
|
337
337
|
|---|---|
|
|
338
338
|
| `.cache()` | Subscribe to the source once; replay all items to subsequent subscribers. |
|
|
339
|
+
| `.share()` | Hot multicast with refCounting — connects on first subscriber, disconnects when the last one leaves. Items are delivered best-effort (no buffering). Re-subscribes to upstream when a new subscriber arrives after all others have left. |
|
|
339
340
|
| `.switchIfEmpty(alternative)` | Switch to `alternative` if source completes without emitting. |
|
|
340
341
|
| `.delaySubscription(ms)` | Delay the actual subscription to the source by `ms` milliseconds. |
|
|
341
342
|
| `.pipe(producer, onRequest, onUnsubscribe)` | Low-level escape hatch for building custom downstream operators. |
|
|
342
343
|
|
|
344
|
+
```typescript
|
|
345
|
+
// share() — multiple subscribers observe the same live upstream
|
|
346
|
+
const hot = Flux.interval(500).share();
|
|
347
|
+
|
|
348
|
+
hot.subscribe(v => console.log('A:', v));
|
|
349
|
+
setTimeout(() => hot.subscribe(v => console.log('B:', v)), 1200);
|
|
350
|
+
// A: 0, A: 1, A: 2, B: 2, A: 3, B: 3, …
|
|
351
|
+
```
|
|
352
|
+
|
|
343
353
|
### FluxSink
|
|
344
354
|
|
|
345
355
|
`Flux.create(emitter => …)` hands the `emitter` callback a `FluxSink<T>` with:
|
|
@@ -413,6 +423,7 @@ sub.unsubscribe(); // cancel at any time
|
|
|
413
423
|
| `Mono.empty()` | Complete immediately without emitting. |
|
|
414
424
|
| `Mono.error(err)` | Signal `onError` immediately. |
|
|
415
425
|
| `Mono.firstWithValue(...sources)` | Race: emit the first value from any of the given `Mono` sources. |
|
|
426
|
+
| `Mono.when(...sources)` | `Mono<void>` that completes when **all** given publishers complete. Values are ignored; the first error is propagated and all other sources are cancelled. |
|
|
416
427
|
|
|
417
428
|
```typescript
|
|
418
429
|
import { Mono } from 'reactor-core-ts';
|
|
@@ -429,6 +440,12 @@ Mono.justOrEmpty(null).subscribe(
|
|
|
429
440
|
() => console.log('empty'),
|
|
430
441
|
);
|
|
431
442
|
// empty
|
|
443
|
+
|
|
444
|
+
// Mono.when — wait for multiple async operations to finish
|
|
445
|
+
Mono.when(
|
|
446
|
+
Mono.fromPromise(saveUser(user)),
|
|
447
|
+
Mono.fromPromise(sendEmail(user)),
|
|
448
|
+
).subscribe(undefined, undefined, () => console.log('all done'));
|
|
432
449
|
```
|
|
433
450
|
|
|
434
451
|
### Mono Transformation
|
|
@@ -439,6 +456,8 @@ Mono.justOrEmpty(null).subscribe(
|
|
|
439
456
|
| `.mapNotNull(fn)` | Transform `T → R | null | undefined`; if result is null/undefined, complete empty. |
|
|
440
457
|
| `.flatMap(fn)` | Map the value to a `Mono<R>`, then subscribe to that inner Mono. |
|
|
441
458
|
| `.flatMapMany(fn)` | Map the value to a `Flux<R>` or `Mono<R>`, returning a `Flux<R>`. |
|
|
459
|
+
| `.then()` | `Mono<void>` — ignore the emitted value; complete when source completes. |
|
|
460
|
+
| `.then(other)` | Ignore the emitted value; subscribe to `other` after source completes and return `other`'s result. |
|
|
442
461
|
| `.thenReturn(value)` | Ignore the emitted value; emit `value` after source completes. |
|
|
443
462
|
| `.delayElement(ms)` | Delay the emitted value by `ms` milliseconds. |
|
|
444
463
|
| `.delayUntil(triggerFn)` | Hold the emitted value until the trigger publisher fires, then forward it. |
|
|
@@ -453,6 +472,18 @@ Mono.just(5)
|
|
|
453
472
|
.flatMapMany(n => Flux.range(0, n))
|
|
454
473
|
.subscribe(v => console.log(v));
|
|
455
474
|
// 0 1 2 3 4
|
|
475
|
+
|
|
476
|
+
// then() — sequence operations, ignore intermediate values
|
|
477
|
+
Mono.just('step 1')
|
|
478
|
+
.then(Mono.just('step 2'))
|
|
479
|
+
.then(Mono.just('step 3'))
|
|
480
|
+
.subscribe(v => console.log(v));
|
|
481
|
+
// 'step 3'
|
|
482
|
+
|
|
483
|
+
// then() with no argument — completion signal only
|
|
484
|
+
Mono.fromPromise(deleteRecord(id))
|
|
485
|
+
.then()
|
|
486
|
+
.subscribe(undefined, undefined, () => console.log('deleted'));
|
|
456
487
|
```
|
|
457
488
|
|
|
458
489
|
### Mono Filtering
|
|
@@ -547,10 +578,16 @@ const value: number | null = await Mono.just(42).toPromise();
|
|
|
547
578
|
|
|
548
579
|
## Sinks
|
|
549
580
|
|
|
550
|
-
Sinks are imperative bridges that let external code push values into a reactive stream. The `Sinks` factory returns a `SinkPublisher<T>` — an object that implements both `Sink<T>` (push API) and `Publisher<T>` (subscribe API).
|
|
581
|
+
Sinks are imperative bridges that let external code push values into a reactive stream. The `Sinks` factory returns a `SinkPublisher<T>` — an object that implements both `Sink<T>` (push API) and `Publisher<T>` (subscribe API), plus a convenience `asFlux()` method that wraps the sink as a full-featured `Flux<T>` with all operators available.
|
|
551
582
|
|
|
552
583
|
```typescript
|
|
553
584
|
import { Sinks, Flux } from 'reactor-core-ts';
|
|
585
|
+
|
|
586
|
+
// asFlux() gives access to all Flux operators
|
|
587
|
+
const sink = Sinks.many().replay().all<number>();
|
|
588
|
+
sink.next(1);
|
|
589
|
+
sink.next(2);
|
|
590
|
+
sink.asFlux().map(n => n * 10).subscribe(v => console.log(v)); // 10 20
|
|
554
591
|
```
|
|
555
592
|
|
|
556
593
|
### `Sinks.empty<T>()`
|
package/dist/index.d.mts
CHANGED
|
@@ -1275,6 +1275,28 @@ declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipeP
|
|
|
1275
1275
|
* @returns A cached, replayable `Flux<T>`.
|
|
1276
1276
|
*/
|
|
1277
1277
|
cache(): Flux<T>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Multicasts this `Flux` to all current subscribers using a refCounting strategy.
|
|
1280
|
+
*
|
|
1281
|
+
* The upstream is subscribed to when the **first** subscriber joins and cancelled
|
|
1282
|
+
* when the **last** subscriber leaves. If a new subscriber arrives after all others
|
|
1283
|
+
* have cancelled, a fresh upstream subscription is created.
|
|
1284
|
+
*
|
|
1285
|
+
* Items are delivered on a best-effort basis: a subscriber that has no outstanding
|
|
1286
|
+
* demand when an item arrives simply misses that item (no buffering). Once the upstream
|
|
1287
|
+
* terminates (complete or error), the terminal signal is replayed to any future subscriber.
|
|
1288
|
+
*
|
|
1289
|
+
* @returns A hot `Flux<T>` that shares a single upstream subscription.
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```typescript
|
|
1293
|
+
* const shared = Flux.interval(100).share();
|
|
1294
|
+
* shared.subscribe(v => console.log('A', v));
|
|
1295
|
+
* setTimeout(() => shared.subscribe(v => console.log('B', v)), 250);
|
|
1296
|
+
* // A 0, A 1, A 2, B 2, A 3, B 3 ...
|
|
1297
|
+
* ```
|
|
1298
|
+
*/
|
|
1299
|
+
share(): Flux<T>;
|
|
1278
1300
|
/**
|
|
1279
1301
|
* Pairs each item with its zero-based index, emitting `[index, item]` tuples.
|
|
1280
1302
|
*
|
|
@@ -1873,6 +1895,23 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
1873
1895
|
* ```
|
|
1874
1896
|
*/
|
|
1875
1897
|
static firstWithValue<T>(...sources: Mono<T>[]): Mono<T>;
|
|
1898
|
+
/**
|
|
1899
|
+
* Returns a `Mono<void>` that completes when **all** given publishers complete.
|
|
1900
|
+
*
|
|
1901
|
+
* Emitted values from the sources are ignored. If any source signals `onError`,
|
|
1902
|
+
* the error is propagated immediately and all other sources are cancelled.
|
|
1903
|
+
* If no sources are provided, completes immediately.
|
|
1904
|
+
*
|
|
1905
|
+
* @param sources - Zero or more publishers to wait on.
|
|
1906
|
+
* @returns A `Mono<void>` that completes once every source has completed.
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```typescript
|
|
1910
|
+
* Mono.when(Mono.delay(100), Mono.delay(200))
|
|
1911
|
+
* .subscribe(undefined, undefined, () => console.log('all done'));
|
|
1912
|
+
* ```
|
|
1913
|
+
*/
|
|
1914
|
+
static when(...sources: Publisher<unknown>[]): Mono<void>;
|
|
1876
1915
|
/**
|
|
1877
1916
|
* Transforms the emitted value using `fn`, producing a `Mono<R>`.
|
|
1878
1917
|
*
|
|
@@ -2057,6 +2096,27 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
2057
2096
|
* ```
|
|
2058
2097
|
*/
|
|
2059
2098
|
thenReturn<R>(value: R): Mono<R>;
|
|
2099
|
+
/**
|
|
2100
|
+
* Ignores the value emitted by this `Mono` and, upon completion, subscribes to `other`
|
|
2101
|
+
* and forwards its result downstream.
|
|
2102
|
+
*
|
|
2103
|
+
* If `other` is omitted, returns a `Mono<void>` that completes when this `Mono` completes.
|
|
2104
|
+
* Errors from this `Mono` are propagated without subscribing to `other`.
|
|
2105
|
+
*
|
|
2106
|
+
* @param other - Optional `Mono<V>` to subscribe to after this `Mono` completes.
|
|
2107
|
+
* @returns `Mono<void>` when called with no argument; `Mono<V>` when `other` is provided.
|
|
2108
|
+
*
|
|
2109
|
+
* @example
|
|
2110
|
+
* ```typescript
|
|
2111
|
+
* // Sequencing: run A, then run B and return B's value
|
|
2112
|
+
* Mono.just('ignored').then(Mono.just(42)).subscribe(v => console.log(v)); // 42
|
|
2113
|
+
*
|
|
2114
|
+
* // Completion signal only
|
|
2115
|
+
* Mono.just('ignored').then().subscribe(undefined, undefined, () => console.log('done'));
|
|
2116
|
+
* ```
|
|
2117
|
+
*/
|
|
2118
|
+
then(): Mono<void>;
|
|
2119
|
+
then<V>(other: Mono<V>): Mono<V>;
|
|
2060
2120
|
/**
|
|
2061
2121
|
* Delays delivery of the emitted value by `ms` milliseconds.
|
|
2062
2122
|
*
|
|
@@ -2261,10 +2321,13 @@ declare const Schedulers: {
|
|
|
2261
2321
|
};
|
|
2262
2322
|
|
|
2263
2323
|
/**
|
|
2264
|
-
* A {@link Sink} that is also a
|
|
2265
|
-
* Callers can push values via the `Sink` interface
|
|
2324
|
+
* A {@link Sink} that is also a {@link Publisher}, with a convenience `asFlux()` accessor.
|
|
2325
|
+
* Callers can push values via the `Sink` interface, subscribe via the `Publisher` interface,
|
|
2326
|
+
* or obtain a full-featured {@link Flux} view via `asFlux()`.
|
|
2266
2327
|
*/
|
|
2267
|
-
type SinkPublisher<T> = Sink<T> & Publisher<T
|
|
2328
|
+
type SinkPublisher<T> = Sink<T> & Publisher<T> & {
|
|
2329
|
+
asFlux(): Flux<T>;
|
|
2330
|
+
};
|
|
2268
2331
|
|
|
2269
2332
|
/**
|
|
2270
2333
|
* Factory namespace for creating hot or replayable sink/publisher pairs.
|
package/dist/index.d.ts
CHANGED
|
@@ -1275,6 +1275,28 @@ declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipeP
|
|
|
1275
1275
|
* @returns A cached, replayable `Flux<T>`.
|
|
1276
1276
|
*/
|
|
1277
1277
|
cache(): Flux<T>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Multicasts this `Flux` to all current subscribers using a refCounting strategy.
|
|
1280
|
+
*
|
|
1281
|
+
* The upstream is subscribed to when the **first** subscriber joins and cancelled
|
|
1282
|
+
* when the **last** subscriber leaves. If a new subscriber arrives after all others
|
|
1283
|
+
* have cancelled, a fresh upstream subscription is created.
|
|
1284
|
+
*
|
|
1285
|
+
* Items are delivered on a best-effort basis: a subscriber that has no outstanding
|
|
1286
|
+
* demand when an item arrives simply misses that item (no buffering). Once the upstream
|
|
1287
|
+
* terminates (complete or error), the terminal signal is replayed to any future subscriber.
|
|
1288
|
+
*
|
|
1289
|
+
* @returns A hot `Flux<T>` that shares a single upstream subscription.
|
|
1290
|
+
*
|
|
1291
|
+
* @example
|
|
1292
|
+
* ```typescript
|
|
1293
|
+
* const shared = Flux.interval(100).share();
|
|
1294
|
+
* shared.subscribe(v => console.log('A', v));
|
|
1295
|
+
* setTimeout(() => shared.subscribe(v => console.log('B', v)), 250);
|
|
1296
|
+
* // A 0, A 1, A 2, B 2, A 3, B 3 ...
|
|
1297
|
+
* ```
|
|
1298
|
+
*/
|
|
1299
|
+
share(): Flux<T>;
|
|
1278
1300
|
/**
|
|
1279
1301
|
* Pairs each item with its zero-based index, emitting `[index, item]` tuples.
|
|
1280
1302
|
*
|
|
@@ -1873,6 +1895,23 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
1873
1895
|
* ```
|
|
1874
1896
|
*/
|
|
1875
1897
|
static firstWithValue<T>(...sources: Mono<T>[]): Mono<T>;
|
|
1898
|
+
/**
|
|
1899
|
+
* Returns a `Mono<void>` that completes when **all** given publishers complete.
|
|
1900
|
+
*
|
|
1901
|
+
* Emitted values from the sources are ignored. If any source signals `onError`,
|
|
1902
|
+
* the error is propagated immediately and all other sources are cancelled.
|
|
1903
|
+
* If no sources are provided, completes immediately.
|
|
1904
|
+
*
|
|
1905
|
+
* @param sources - Zero or more publishers to wait on.
|
|
1906
|
+
* @returns A `Mono<void>` that completes once every source has completed.
|
|
1907
|
+
*
|
|
1908
|
+
* @example
|
|
1909
|
+
* ```typescript
|
|
1910
|
+
* Mono.when(Mono.delay(100), Mono.delay(200))
|
|
1911
|
+
* .subscribe(undefined, undefined, () => console.log('all done'));
|
|
1912
|
+
* ```
|
|
1913
|
+
*/
|
|
1914
|
+
static when(...sources: Publisher<unknown>[]): Mono<void>;
|
|
1876
1915
|
/**
|
|
1877
1916
|
* Transforms the emitted value using `fn`, producing a `Mono<R>`.
|
|
1878
1917
|
*
|
|
@@ -2057,6 +2096,27 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
2057
2096
|
* ```
|
|
2058
2097
|
*/
|
|
2059
2098
|
thenReturn<R>(value: R): Mono<R>;
|
|
2099
|
+
/**
|
|
2100
|
+
* Ignores the value emitted by this `Mono` and, upon completion, subscribes to `other`
|
|
2101
|
+
* and forwards its result downstream.
|
|
2102
|
+
*
|
|
2103
|
+
* If `other` is omitted, returns a `Mono<void>` that completes when this `Mono` completes.
|
|
2104
|
+
* Errors from this `Mono` are propagated without subscribing to `other`.
|
|
2105
|
+
*
|
|
2106
|
+
* @param other - Optional `Mono<V>` to subscribe to after this `Mono` completes.
|
|
2107
|
+
* @returns `Mono<void>` when called with no argument; `Mono<V>` when `other` is provided.
|
|
2108
|
+
*
|
|
2109
|
+
* @example
|
|
2110
|
+
* ```typescript
|
|
2111
|
+
* // Sequencing: run A, then run B and return B's value
|
|
2112
|
+
* Mono.just('ignored').then(Mono.just(42)).subscribe(v => console.log(v)); // 42
|
|
2113
|
+
*
|
|
2114
|
+
* // Completion signal only
|
|
2115
|
+
* Mono.just('ignored').then().subscribe(undefined, undefined, () => console.log('done'));
|
|
2116
|
+
* ```
|
|
2117
|
+
*/
|
|
2118
|
+
then(): Mono<void>;
|
|
2119
|
+
then<V>(other: Mono<V>): Mono<V>;
|
|
2060
2120
|
/**
|
|
2061
2121
|
* Delays delivery of the emitted value by `ms` milliseconds.
|
|
2062
2122
|
*
|
|
@@ -2261,10 +2321,13 @@ declare const Schedulers: {
|
|
|
2261
2321
|
};
|
|
2262
2322
|
|
|
2263
2323
|
/**
|
|
2264
|
-
* A {@link Sink} that is also a
|
|
2265
|
-
* Callers can push values via the `Sink` interface
|
|
2324
|
+
* A {@link Sink} that is also a {@link Publisher}, with a convenience `asFlux()` accessor.
|
|
2325
|
+
* Callers can push values via the `Sink` interface, subscribe via the `Publisher` interface,
|
|
2326
|
+
* or obtain a full-featured {@link Flux} view via `asFlux()`.
|
|
2266
2327
|
*/
|
|
2267
|
-
type SinkPublisher<T> = Sink<T> & Publisher<T
|
|
2328
|
+
type SinkPublisher<T> = Sink<T> & Publisher<T> & {
|
|
2329
|
+
asFlux(): Flux<T>;
|
|
2330
|
+
};
|
|
2268
2331
|
|
|
2269
2332
|
/**
|
|
2270
2333
|
* Factory namespace for creating hot or replayable sink/publisher pairs.
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var O=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var j=(a,n)=>{for(var e in n)O(a,e,{get:n[e],enumerable:!0})},Q=(a,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of K(n))!L.call(a,t)&&t!==e&&O(a,t,{get:()=>n[t],enumerable:!(r=U(n,t))||r.enumerable});return a};var J=a=>Q(O({},"__esModule",{value:!0}),a);var H={};j(H,{Flux:()=>C,Mono:()=>h,Schedulers:()=>z,Signal:()=>x,Sinks:()=>Z});module.exports=J(H);var T=class{constructor(){this.entries=new Map;this.terminated=!1;this.terminalError=null}shouldReplayTerminalOnSubscribe(){return this.terminated}onDemandGranted(n,e){}onUnsubscribed(n,e){}onSubscribed(n,e){}deliverError(n,e){e.cancelled||n.onError(this.terminalError)}deliverComplete(n,e){e.cancelled||n.onComplete()}clearEntriesAfterComplete(){return!0}error(n){if(!this.terminated){this.terminated=!0,this.terminalError=n;for(let[e,r]of this.entries)this.deliverError(e,r);this.entries.clear()}}complete(){if(!this.terminated){this.terminated=!0;for(let[n,e]of this.entries)this.deliverComplete(n,e);this.clearEntriesAfterComplete()&&this.entries.clear()}}subscribe(n){if(this.shouldReplayTerminalOnSubscribe()){let t={request(){},unsubscribe(){}};return n.onSubscribe(t),this.terminalError?n.onError(this.terminalError):n.onComplete(),t}let e=this.createEntry();this.entries.set(n,e);let r={request:t=>{if(!e.cancelled){if(t<=0){e.cancelled=!0,this.entries.delete(n),n.onError(new Error(`request must be > 0, but was ${t}`));return}e.demand=Math.min(e.demand+t,Number.MAX_SAFE_INTEGER),this.onDemandGranted(n,e)}},unsubscribe:()=>{e.cancelled=!0,this.entries.delete(n),this.onUnsubscribed(n,e)}};return n.onSubscribe(r),this.onSubscribed(n,e),r}};var w=class extends T{constructor(){super(...arguments);this.history=[]}createEntry(){return{position:0,demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.history.length===0}deliverError(e,r){this.drainEntry(e,r),r.cancelled||e.onError(this.terminalError)}deliverComplete(e,r){r.cancelled||this.drainEntry(e,r)}clearEntriesAfterComplete(){return!1}onDemandGranted(e,r){this.drainEntry(e,r)}next(e){if(!this.terminated){this.history.push(e);for(let[r,t]of this.entries)t.cancelled||this.drainEntry(r,t)}}drainEntry(e,r){if(!(r.cancelled||r.draining)){r.draining=!0;try{for(;r.demand>0&&r.position<this.history.length;)if(r.demand--,e.onNext(this.history[r.position++]),r.cancelled)return;r.position>=this.history.length&&this.terminated&&(this.entries.delete(e),this.terminalError?e.onError(this.terminalError):e.onComplete())}finally{r.draining=!1}}}};var x={next(a){return{kind:"next",value:a}},error(a){return{kind:"error",error:a}},complete(){return{kind:"complete"}}};var R=class{constructor(n){this.source=n}subscribe(n,e,r){if(n!==void 0&&typeof n=="object")return this.source.subscribe(n);let t=n,o=this.defaultDemand();return this.source.subscribe({onSubscribe(u){u.request(o)},onNext:t??(()=>{}),onError:e??(u=>{throw u}),onComplete:r??(()=>{})})}switchIfEmpty(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=!1,i=0,s={request(l){if(!u){if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}i=Math.min(i+l,Number.MAX_SAFE_INTEGER),t?t.request(l):r.request(l)}},unsubscribe(){u=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(l){r=l,e.onSubscribe(s)},onNext(l){o=!0,e.onNext(l)},onError(l){e.onError(l)},onComplete(){if(o||u){e.onComplete();return}t=n.subscribe({onSubscribe(l){t=l,i>0&&t.request(i)},onNext(l){e.onNext(l)},onError(l){e.onError(l)},onComplete(){e.onComplete()}})}}),s}})}onErrorReturn(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){o||(t=n.subscribe({onSubscribe(l){t=l,u>0&&t.request(u)},onNext(l){e.onNext(l)},onError(l){e.onError(l)},onComplete(){e.onComplete()}}))},onComplete(){e.onComplete()}}),i}})}onErrorContinue(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){n(t)?e.onComplete():e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doFirst(n){return this.wrapSource({subscribe:e=>{let r=!0,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(r){r=!1;try{n()}catch{}}e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}doOnNext(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)}catch{}e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doOnError(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n(t)}catch{}e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doOnSubscribe(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});try{n(r)}catch{}return e.onSubscribe(r),r}})}publishOn(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){n.schedule(()=>e.onNext(t))},onError(t){n.schedule(()=>e.onError(t))},onComplete(){n.schedule(()=>e.onComplete())}});return e.onSubscribe(r),r}})}onErrorResume(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){t=c,u>0&&c.request(u)},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}})},onComplete(){e.onComplete()}}),i}})}onErrorMap(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{e.onError(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}timeout(n,e){return this.wrapSource({subscribe:r=>{let t={request(){},unsubscribe(){}},o=null,u=!1,i=!1,s=!1,l=0,c=null,b=()=>{c!==null&&(clearTimeout(c),c=null)},p=()=>{b(),c=setTimeout(()=>{u||s||(i=!0,t.unsubscribe(),e?o=e.subscribe({onSubscribe(S){o=S,l>0&&S.request(l)},onNext(S){!u&&!s&&r.onNext(S)},onError(S){!u&&!s&&(s=!0,r.onError(S))},onComplete(){!u&&!s&&(s=!0,r.onComplete())}}):(s=!0,r.onError(new Error(`TimeoutError: no item within ${n}ms`))))},n)},f={request(S){if(!(u||s)){if(S<=0){r.onError(new Error(`request must be > 0, but was ${S}`));return}l=Math.min(l+S,Number.MAX_SAFE_INTEGER),o?o.request(S):t.request(S)}},unsubscribe(){u=!0,b(),t.unsubscribe(),o?.unsubscribe()}};return this.source.subscribe({onSubscribe(S){t=S,r.onSubscribe(f),p()},onNext(S){u||i||(p(),r.onNext(S))},onError(S){b(),!u&&!s&&(s=!0,r.onError(S))},onComplete(){b(),!u&&!s&&(s=!0,r.onComplete())}}),f}})}delaySubscription(n){return this.wrapSource({subscribe:e=>{let r=null,t=!1,o=0,u={request(l){if(!t){if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}o=Math.min(o+l,Number.MAX_SAFE_INTEGER),r&&r.request(l)}},unsubscribe(){t=!0,r?.unsubscribe()}};e.onSubscribe(u);let i=setTimeout(()=>{t||this.source.subscribe({onSubscribe(l){r=l,o>0&&l.request(o)},onNext(l){t||e.onNext(l)},onError(l){t||e.onError(l)},onComplete(){t||e.onComplete()}})},n),s=u.unsubscribe.bind(u);return u.unsubscribe=()=>{clearTimeout(i),s()},u}})}log(n="reactor"){return this.wrapSource({subscribe:e=>{let r=`[${n}]`,t;return this.source.subscribe({onSubscribe(o){console.log(`${r} onSubscribe`),t={request(u){console.log(`${r} request(${u})`),o.request(u)},unsubscribe(){console.log(`${r} cancel`),o.unsubscribe()}},e.onSubscribe(t)},onNext(o){console.log(`${r} onNext(${JSON.stringify(o)})`),e.onNext(o)},onError(o){console.error(`${r} onError: ${o.message}`),e.onError(o)},onComplete(){console.log(`${r} onComplete`),e.onComplete()}}),t}})}doOnRequest(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}}),t={request(o){try{n(o)}catch{}r.request(o)},unsubscribe(){r.unsubscribe()}};return e.onSubscribe(t),t}})}doOnEach(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(x.next(t))}catch{}e.onNext(t)},onError(t){try{n(x.error(t))}catch{}e.onError(t)},onComplete(){try{n(x.complete())}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}subscribeOn(n){return this.wrapSource({subscribe:e=>{let r=null,t=0,o=!1,u={request(i){if(!o){if(i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}r?r.request(i):t=Math.min(t+i,Number.MAX_SAFE_INTEGER)}},unsubscribe(){o=!0,r?.unsubscribe()}};return e.onSubscribe(u),n.schedule(()=>{o||(r=this.source.subscribe({onSubscribe(i){},onNext(i){e.onNext(i)},onError(i){e.onError(i)},onComplete(){e.onComplete()}}),t>0&&r.request(t))}),u}})}};var I=class{schedule(n){n()}};var X=class{schedule(n){Promise.resolve().then(n)}};var $=class{schedule(n){setTimeout(n,0)}};var D=class{constructor(n){this.delay=n}schedule(n){let e=setTimeout(n,this.delay);return{cancel:()=>clearTimeout(e)}}};var B=class{constructor(n){this.interval=n}schedule(n){let e=setInterval(n,this.interval);return{cancel:()=>clearInterval(e)}}};var z={immediate:()=>new I,micro:()=>new X,macro:()=>new $,delay:a=>new D(a),interval:a=>new B(a)};var C=class a extends R{constructor(n){super(n)}defaultDemand(){return Number.MAX_SAFE_INTEGER}wrapSource(n){return new a(n)}static from(n){return new a(n)}static generate(n){return new a({subscribe(e){let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=!1,c=()=>{if(!(l||s)){l=!0;try{for(;t>0&&r.length>0;)if(t--,e.onNext(r.shift()),s)return;!u&&r.length===0&&o&&(u=!0,i?e.onError(i):e.onComplete())}finally{l=!1}}},b={next(f){o||s||(t>0?(t--,e.onNext(f)):r.push(f))},error(f){o||s||(o=!0,i=f,c())},complete(){o||s||(o=!0,c())}},p={request(f){if(!s){if(f<=0){e.onError(new Error(`request must be > 0, but was ${f}`));return}t=Math.min(t+f,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){s=!0,r.length=0}};e.onSubscribe(p);try{n(b)}catch(f){o||(o=!0,i=f instanceof Error?f:new Error(String(f)),c())}return p}})}static fromIterable(n){return a.generate(e=>{for(let r of n)e.next(r);e.complete()})}static range(n,e){return a.generate(r=>{for(let t=0;t<e;t++)r.next(n+t);r.complete()})}static empty(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),n.onComplete(),e}})}static defer(n){return new a({subscribe(e){return n().subscribe(e)}})}static just(...n){return a.fromIterable(n)}static error(n){return new a({subscribe(e){let r={request(){},unsubscribe(){}};return e.onSubscribe(r),e.onError(n),r}})}static never(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),e}})}static create(n){return new a({subscribe(e){let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=[],c=[],b=[],p=()=>{for(let d of b)try{d()}catch{}},f=()=>{if(!(s||o)){s=!0;try{for(;t>0&&r.length>0&&!o;)t--,e.onNext(r.shift());u&&r.length===0&&!o&&(i?e.onError(i):e.onComplete())}finally{s=!1}}},S={next(d){o||u||(r.push(d),f())},error(d){o||u||(u=!0,i=d,p(),f())},complete(){o||u||(u=!0,p(),f())},get requested(){return t},onRequest(d){return l.push(d),S},onCancel(d){return c.push(d),S},onDispose(d){return b.push(d),S}},m={request(d){if(!(o||u&&r.length===0)){if(d<=0){e.onError(new Error(`request must be > 0, but was ${d}`));return}t=Math.min(t+d,Number.MAX_SAFE_INTEGER);for(let E of l)try{E(d)}catch{}f()}},unsubscribe(){if(!o){o=!0,r.length=0;for(let d of c)try{d()}catch{}p()}}};e.onSubscribe(m);try{n(S)}catch(d){!u&&!o&&S.error(d instanceof Error?d:new Error(String(d)))}return m}})}static using(n,e,r){return a.defer(()=>{let t=n();return a.from(e(t)).doFinally(()=>{try{r(t)}catch{}})})}static merge(...n){return n.length===0?a.empty():n.length===1?a.from(n[0]):new a({subscribe(e){let r=n.length,t=0,o=!1,u=!1,i=new Array(r),s=c=>{if(!u){u=!0;for(let b of i)b?.unsubscribe();c?e.onError(c):e.onComplete()}},l={request(c){if(!(o||u)){if(c<=0){s(new Error(`request must be > 0, but was ${c}`));return}for(let b of i)b.request(c)}},unsubscribe(){o=!0;for(let c of i)c?.unsubscribe()}};for(let c=0;c<r;c++){let b;n[c].subscribe({onSubscribe(p){b=p},onNext(p){!o&&!u&&e.onNext(p)},onError(p){s(p)},onComplete(){++t===r&&s()}}),i[c]=b}return e.onSubscribe(l),l}})}static firstWithValue(...n){return new a({subscribe(e){if(n.length===0){let c={request(){},unsubscribe(){}};return e.onSubscribe(c),e.onComplete(),c}let r=n.length,t=!1,o=!1,u=0,i=null,s=new Array(r),l={request(c){if(!o)for(let b of s)b.request(c)},unsubscribe(){o=!0;for(let c of s)c?.unsubscribe()}};for(let c=0;c<r;c++){let b=c,p;n[b].subscribe({onSubscribe(f){p=f},onNext(f){if(!(o||t)){t=!0;for(let S=0;S<r;S++)S!==b&&s[S]?.unsubscribe();e.onNext(f),e.onComplete()}},onError(f){o||t||(i=f,++u===r&&e.onError(i))},onComplete(){o||t||++u===r&&e.onComplete()}}),s[b]=p}return e.onSubscribe(l),l}})}static interval(n){return new a({subscribe(e){let r=0,t=0,o=!1,u=setInterval(()=>{o||r>0&&(r--,e.onNext(t++))},n),i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}r=Math.min(r+s,Number.MAX_SAFE_INTEGER)}},unsubscribe(){o=!0,clearInterval(u)}};return e.onSubscribe(i),i}})}static zip(n,e){return n.length===0?a.empty():new a({subscribe(r){let t=n.length,o=0,u=!1,i=!1,s=Array.from({length:t},()=>[]),l=new Array(t).fill(!1),c=new Array(t),b=()=>{for(;!u&&!i&&o>0&&s.every(f=>f.length>0);){o--;let f=s.map(m=>m.shift()),S;try{S=e(...f)}catch(m){i=!0;for(let d of c)d?.unsubscribe();r.onError(m instanceof Error?m:new Error(String(m)));return}r.onNext(S);for(let m=0;m<t;m++)l[m]||c[m].request(1)}if(!i&&l.some((f,S)=>f&&s[S].length===0)){i=!0;for(let f of c)f?.unsubscribe();r.onComplete()}},p={request(f){if(!(u||i)){if(f<=0){r.onError(new Error(`request must be > 0, but was ${f}`));return}o=Math.min(o+f,Number.MAX_SAFE_INTEGER),b()}},unsubscribe(){u=!0;for(let f of c)f?.unsubscribe()}};for(let f=0;f<t;f++){let S=f,m;n[S].subscribe({onSubscribe(d){m=d},onNext(d){u||i||(s[S].push(d),b())},onError(d){if(!(u||i)){i=!0;for(let E of c)E?.unsubscribe();r.onError(d)}},onComplete(){u||i||(l[S]=!0,b())}}),c[S]=m}r.onSubscribe(p);for(let f=0;f<t;f++)c[f].request(1);return p}})}static combineLatest(n,e){return n.length===0?a.empty():new a({subscribe(r){let t=n.length,o=0,u=!1,i=!1,s=[],l=new Array(t).fill(void 0),c=new Array(t).fill(!1),b=new Array(t).fill(!1),p=new Array(t),f=()=>{for(;!u&&!i&&o>0&&s.length>0;)o--,r.onNext(s.shift());!i&&b.every(Boolean)&&s.length===0&&(i=!0,r.onComplete())},S={request(m){if(!(u||i)){if(m<=0){r.onError(new Error(`request must be > 0, but was ${m}`));return}o=Math.min(o+m,Number.MAX_SAFE_INTEGER),f()}},unsubscribe(){u=!0;for(let m of p)m?.unsubscribe()}};for(let m=0;m<t;m++){let d=m,E;n[d].subscribe({onSubscribe(N){E=N},onNext(N){if(!(u||i)&&(l[d]=N,c[d]=!0,c.every(Boolean))){let G;try{G=e(...l)}catch(V){i=!0;for(let W of p)W?.unsubscribe();r.onError(V instanceof Error?V:new Error(String(V)));return}s.push(G),f()}},onError(N){if(!(u||i)){i=!0;for(let G of p)G?.unsubscribe();r.onError(N)}},onComplete(){u||i||(b[d]=!0,f())}}),p[d]=E}r.onSubscribe(S);for(let m=0;m<t;m++)p[m].request(Number.MAX_SAFE_INTEGER);return S}})}map(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{e.onNext(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}mapNotNull(n){return new a({subscribe:e=>{let r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){try{let u=n(o);u!=null?e.onNext(u):r.request(1)}catch(u){e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}handle(n){return new a({subscribe:e=>{let r,t=!1,o=this.source.subscribe({onSubscribe(u){r=u},onNext(u){if(t)return;let i=!1,s={next(l){!i&&!t&&(i=!0,e.onNext(l))},error(l){t||(t=!0,e.onError(l))},complete(){t||(t=!0,e.onComplete())}};try{n(u,s)}catch(l){t||(t=!0,e.onError(l instanceof Error?l:new Error(String(l))))}!t&&!i&&r.request(1)},onError(u){t||e.onError(u)},onComplete(){t||e.onComplete()}});return e.onSubscribe(o),o}})}flatMap(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=new Set,o=!1,u=!1,i=!1,s=0,l=b=>{if(!u){u=!0,r.unsubscribe();for(let p of t)p.unsubscribe();t.clear(),b?e.onError(b):e.onComplete()}},c={request(b){if(!(o||u)){if(b<=0){l(new Error(`request must be > 0, but was ${b}`));return}s=Math.min(s+b,Number.MAX_SAFE_INTEGER);for(let p of t)p.request(b)}},unsubscribe(){o=!0,r.unsubscribe();for(let b of t)b.unsubscribe();t.clear()}};return this.source.subscribe({onSubscribe(b){r=b,e.onSubscribe(c)},onNext(b){if(o||u)return;let p;try{p=n(b)}catch(S){l(S instanceof Error?S:new Error(String(S)));return}let f=p.subscribe({onSubscribe(S){},onNext(S){!o&&!u&&e.onNext(S)},onError(S){l(S)},onComplete(){t.delete(f),!u&&i&&t.size===0&&l()}});t.add(f),s>0&&f.request(s)},onError(b){l(b)},onComplete(){i=!0,!u&&t.size===0&&l()}}),r.request(Number.MAX_SAFE_INTEGER),c}})}concatMap(n){return new a({subscribe:e=>{let r,t=null,o=!1,u=!1,i=!1,s=c=>{u||(u=!0,r?.unsubscribe(),t?.unsubscribe(),t=null,c?e.onError(c):e.onComplete())},l={request(c){if(!(o||u)){if(c<=0){s(new Error(`request must be > 0, but was ${c}`));return}t?t.request(c):r.request(1)}},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(c){r=c,e.onSubscribe(l)},onNext(c){if(o||u)return;let b;try{b=n(c)}catch(p){s(p instanceof Error?p:new Error(String(p)));return}b.subscribe({onSubscribe(p){t=p,p.request(Number.MAX_SAFE_INTEGER)},onNext(p){!o&&!u&&e.onNext(p)},onError(p){s(p)},onComplete(){o||u||(t=null,i?s():r.request(1))}})},onError(c){s(c)},onComplete(){i=!0,t===null&&s()}}),l}})}switchMap(n){return new a({subscribe:e=>{let r,t=null,o=!1,u=!1,i=!1,s=0,l=0,c=p=>{u||(u=!0,r?.unsubscribe(),t?.unsubscribe(),t=null,p?e.onError(p):e.onComplete())},b={request(p){if(!(o||u)){if(p<=0){c(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),t&&t.request(p)}},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(p){r=p,e.onSubscribe(b)},onNext(p){if(o||u)return;t?.unsubscribe(),t=null;let f=++l,S;try{S=n(p)}catch(m){c(m instanceof Error?m:new Error(String(m)));return}S.subscribe({onSubscribe(m){if(l!==f||o||u){m.unsubscribe();return}t=m,s>0&&m.request(s)},onNext(m){l===f&&!o&&!u&&e.onNext(m)},onError(m){l===f&&c(m)},onComplete(){l!==f||o||u||(t=null,i&&c())}})},onError(p){c(p)},onComplete(){i=!0,t===null&&c()}}),r.request(Number.MAX_SAFE_INTEGER),b}})}filter(n){return new a({subscribe:e=>{let r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){try{n(o)?e.onNext(o):r.request(1)}catch(u){e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}filterWhen(n){return this.concatMap(e=>a.from(n(e)).filter(r=>r).map(()=>e))}cast(){return new a(this.source)}take(n){return n<=0?a.empty():new a({subscribe:e=>{let r,t=0,o=!1,u={request(i){o||r?.request(i)},unsubscribe(){o=!0,r?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){o||(e.onNext(i),++t>=n&&(o=!0,r.unsubscribe(),e.onComplete()))},onError(i){o||e.onError(i)},onComplete(){o||e.onComplete()}}),u}})}takeWhile(n){return new a({subscribe:e=>{let r,t=!1,o={request(u){t||r?.request(u)},unsubscribe(){t=!0,r?.unsubscribe()}};return this.source.subscribe({onSubscribe(u){r=u,e.onSubscribe(o)},onNext(u){if(!t)try{n(u)?e.onNext(u):(t=!0,r.unsubscribe(),e.onComplete())}catch(i){t=!0,e.onError(i instanceof Error?i:new Error(String(i)))}},onError(u){t||e.onError(u)},onComplete(){t||e.onComplete()}}),o}})}takeUntilOther(n){return new a({subscribe:e=>{let r,t,o=!1,u={request(i){o||r?.request(i)},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return t=n.subscribe({onSubscribe(i){t=i,i.request(1)},onNext(i){o||(o=!0,r?.unsubscribe(),e.onComplete())},onError(i){o||(o=!0,e.onError(i))},onComplete(){}}),this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){o||e.onNext(i)},onError(i){o||e.onError(i)},onComplete(){o||(o=!0,t?.unsubscribe(),e.onComplete())}}),u}})}defaultIfEmpty(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){r=!0,e.onNext(o)},onError(o){e.onError(o)},onComplete(){r||e.onNext(n),e.onComplete()}});return e.onSubscribe(t),t}})}retry(n=Number.MAX_SAFE_INTEGER){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=0,o=!1,u=0,i=0,s={request(c){if(!o){if(c<=0){e.onError(new Error(`request must be > 0, but was ${c}`));return}t=Math.min(t+c,Number.MAX_SAFE_INTEGER),r.request(c)}},unsubscribe(){o=!0,r.unsubscribe()}},l=()=>{let c=++i;this.source.subscribe({onSubscribe(b){if(c!==i){b.unsubscribe();return}r=b,t>0&&b.request(t)},onNext(b){!o&&c===i&&e.onNext(b)},onError(b){o||c!==i||(u<n?(u++,l()):e.onError(b))},onComplete(){!o&&c===i&&e.onComplete()}})};return e.onSubscribe(s),l(),s}})}scan(n){return new a({subscribe:e=>{let r,t=!1,o=this.source.subscribe({onSubscribe(u){},onNext(u){r=t?n(r,u):u,t=!0,e.onNext(r)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}scanWith(n,e){return new a({subscribe:r=>{let t=n(),o=this.source.subscribe({onSubscribe(u){},onNext(u){t=e(t,u),r.onNext(t)},onError(u){r.onError(u)},onComplete(){r.onComplete()}});return r.onSubscribe(o),o}})}zipWith(n,e){return new a({subscribe:r=>{let t=[],o=[],u=!1,i=!1,s=!1,l=!1,c={request(){},unsubscribe(){}},b={request(){},unsubscribe(){}},p=m=>{l||(l=!0,c.unsubscribe(),b.unsubscribe(),m?r.onError(m):r.onComplete())},f={request(m){if(!(s||l)){if(m<=0){p(new Error(`request must be > 0, but was ${m}`));return}c.request(m),b.request(m)}},unsubscribe(){s=!0,c.unsubscribe(),b.unsubscribe()}},S=()=>{for(;t.length>0&&o.length>0;){if(s||l)return;let m=t.shift(),d=o.shift();try{r.onNext(e(m,d))}catch(E){p(E instanceof Error?E:new Error(String(E)));return}}(u&&t.length===0||i&&o.length===0)&&p()};return this.source.subscribe({onSubscribe(m){c=m,r.onSubscribe(f)},onNext(m){!s&&!l&&(t.push(m),S())},onError(m){p(m)},onComplete(){!s&&!l&&(u=!0,S())}}),b=n.subscribe({onSubscribe(m){b=m},onNext(m){!s&&!l&&(o.push(m),S())},onError(m){p(m)},onComplete(){!s&&!l&&(i=!0,S())}}),f}})}doOnComplete(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}doOnTerminate(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n()}catch{}e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}doOnCancel(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}}),t={request(o){r.request(o)},unsubscribe(){try{n()}catch{}r.unsubscribe()}};return e.onSubscribe(t),t}})}doFinally(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){try{n()}catch{}e.onError(o)},onComplete(){try{n()}catch{}e.onComplete()}}),t={request(o){r.request(o)},unsubscribe(){try{n()}catch{}r.unsubscribe()}};return e.onSubscribe(t),t}})}pipe(n,e,r){return new a({subscribe:t=>{n(u=>t.onNext(u),u=>t.onError(u),()=>t.onComplete());let o={request:e,unsubscribe:r};return t.onSubscribe(o),o}})}first(){return h.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(r)},onError(r){n.error(r)},onComplete(){n.complete()}});e.request(1)})}last(){return h.generate(n=>{let e,r=!1;this.source.subscribe({onSubscribe(o){},onNext(o){e=o,r=!0},onError(o){n.error(o)},onComplete(){r?n.next(e):n.complete()}}).request(Number.MAX_SAFE_INTEGER)})}count(){return h.generate(n=>{let e=0;this.source.subscribe({onSubscribe(t){},onNext(t){e++},onError(t){n.error(t)},onComplete(){n.next(e)}}).request(Number.MAX_SAFE_INTEGER)})}hasElements(){return h.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(!0)},onError(r){n.error(r)},onComplete(){n.next(!1)}});e.request(1)})}any(n){return h.generate(e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)&&(r.unsubscribe(),e.next(!0))}catch(o){e.error(o instanceof Error?o:new Error(String(o)))}},onError(t){e.error(t)},onComplete(){e.next(!1)}});r.request(Number.MAX_SAFE_INTEGER)})}all(n){return h.generate(e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)||(r.unsubscribe(),e.next(!1))}catch(o){e.error(o instanceof Error?o:new Error(String(o)))}},onError(t){e.error(t)},onComplete(){e.next(!0)}});r.request(Number.MAX_SAFE_INTEGER)})}none(n){return this.any(n).map(e=>!e)}elementAt(n,e){return h.generate(r=>{let t=0,o=this.source.subscribe({onSubscribe(u){},onNext(u){t++===n&&(o.unsubscribe(),r.next(u))},onError(u){r.error(u)},onComplete(){e!==void 0?r.next(e):r.complete()}});o.request(Number.MAX_SAFE_INTEGER)})}collect(n=!1){return h.generate(e=>{let r=[];this.source.subscribe({onSubscribe(o){},onNext(o){r.push(o)},onError(o){e.error(o)},onComplete(){e.next(r)}}).request(Number.MAX_SAFE_INTEGER)})}collectList(){return this.collect()}sort(n){return a.defer(()=>a.from(this.collect().map(e=>(e.sort(n),e)).flatMapMany(e=>a.fromIterable(e))))}buffer(n){return new a({subscribe:e=>{let r=[],t=this.source.subscribe({onSubscribe(o){},onNext(o){r.push(o),r.length>=n&&(e.onNext(r),r=[])},onError(o){e.onError(o)},onComplete(){r.length>0&&e.onNext(r),e.onComplete()}});return e.onSubscribe(t),t}})}cache(){let n=new w,e=!1;return new a({subscribe:r=>(e||(e=!0,this.source.subscribe({onSubscribe(t){t.request(Number.MAX_SAFE_INTEGER)},onNext(t){n.next(t)},onError(t){n.error(t)},onComplete(){n.complete()}})),n.subscribe(r))})}indexed(){return new a({subscribe:n=>{let e=0,r=this.source.subscribe({onSubscribe(t){},onNext(t){n.onNext([e++,t])},onError(t){n.onError(t)},onComplete(){n.onComplete()}});return n.onSubscribe(r),r}})}skip(n){return new a({subscribe:e=>{let r=0,t,o=this.source.subscribe({onSubscribe(u){t=u},onNext(u){r++<n?t.request(1):e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}skipWhile(n){return new a({subscribe:e=>{let r=!0,t,o=this.source.subscribe({onSubscribe(u){t=u},onNext(u){if(r&&n(u)){t.request(1);return}r=!1,e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}skipUntil(n){return new a({subscribe:e=>{let r=!0,t,o=n.subscribe({onSubscribe(u){},onNext(u){r=!1,o.unsubscribe()},onError(u){e.onError(u)},onComplete(){}});return o.request(1),t=this.source.subscribe({onSubscribe(u){},onNext(u){r?t.request(1):e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}}),e.onSubscribe({request(u){t.request(u)},unsubscribe(){t.unsubscribe(),o.unsubscribe()}}),{request(u){t.request(u)},unsubscribe(){t.unsubscribe(),o.unsubscribe()}}}})}distinct(){return new a({subscribe:n=>{let e=new Set,r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){e.has(o)?r.request(1):(e.add(o),n.onNext(o))},onError(o){n.onError(o)},onComplete(){n.onComplete()}});return n.onSubscribe(t),t}})}distinctUntilChanged(n=(e,r)=>e!==r){return new a({subscribe:e=>{let r,t=!0,o,u=this.source.subscribe({onSubscribe(i){o=i},onNext(i){t||n(r,i)?(t=!1,r=i,e.onNext(i)):o.request(1)},onError(i){e.onError(i)},onComplete(){e.onComplete()}});return e.onSubscribe(u),u}})}delayElements(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i=!1,s={request(l){if(o)return;if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}let c=u===0;u=Math.min(u+l,Number.MAX_SAFE_INTEGER),c&&t===null&&r.request(1)},unsubscribe(){o=!0,t?.cancel(),t=null,r.unsubscribe()}};return this.source.subscribe({onSubscribe(l){r=l,e.onSubscribe(s)},onNext(l){t=z.delay(n).schedule(()=>{t=null,!o&&(u--,e.onNext(l),!o&&(i?e.onComplete():u>0&&r.request(1)))})},onError(l){t?.cancel(),t=null,e.onError(l)},onComplete(){i=!0,t===null&&!o&&e.onComplete()}}),s}})}concatWith(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){e.onError(s)},onComplete(){o||(t=n.subscribe({onSubscribe(s){t=s,u>0&&t.request(u)},onNext(s){e.onNext(s)},onError(s){e.onError(s)},onComplete(){e.onComplete()}}))}}),i}})}mergeWith(n){return new a({subscribe:e=>{let r=0,t=!1,o=!1,u={request(){},unsubscribe(){}},i={request(){},unsubscribe(){}},s=b=>{o||(o=!0,u.unsubscribe(),i.unsubscribe(),b?e.onError(b):e.onComplete())},l=()=>{!o&&++r===2&&s()},c={request(b){if(!(t||o)){if(b<=0){s(new Error(`request must be > 0, but was ${b}`));return}u.request(b),i.request(b)}},unsubscribe(){t=!0,u.unsubscribe(),i.unsubscribe()}};return this.source.subscribe({onSubscribe(b){u=b,e.onSubscribe(c)},onNext(b){!t&&!o&&e.onNext(b)},onError(b){s(b)},onComplete(){l()}}),i=n.subscribe({onSubscribe(b){},onNext(b){!t&&!o&&e.onNext(b)},onError(b){s(b)},onComplete(){l()}}),c}})}reduce(n){return h.generate(e=>{let r,t=!1;this.source.subscribe({onSubscribe(u){},onNext(u){r=t?n(r,u):u,t=!0},onError(u){e.error(u)},onComplete(){t?e.next(r):e.complete()}}).request(Number.MAX_SAFE_INTEGER)})}reduceWith(n,e){return h.generate(r=>{let t=n();this.source.subscribe({onSubscribe(u){},onNext(u){t=e(t,u)},onError(u){r.error(u)},onComplete(){r.next(t)}}).request(Number.MAX_SAFE_INTEGER)})}then(){return h.generate(n=>{this.source.subscribe({onSubscribe(r){},onNext(r){},onError(r){n.error(r)},onComplete(){n.next(void 0)}}).request(Number.MAX_SAFE_INTEGER)})}thenEmpty(n){return this.then().flatMap(()=>h.from({subscribe(e){let r=n.subscribe({onSubscribe(t){},onNext(t){},onError(t){e.onError(t)},onComplete(){e.onNext(void 0),e.onComplete()}});return e.onSubscribe(r),r}}))}retryWhen(n){return new a({subscribe:e=>{let r=[],t=null,o=0,u=m=>{r.push(m),i()},i=()=>{for(;o>0&&r.length>0&&t;)o--,t.onNext(r.shift())},s=new a({subscribe(m){t=m;let d={request(E){o=Math.min(o+E,Number.MAX_SAFE_INTEGER),i()},unsubscribe(){t=null}};return m.onSubscribe(d),d}}),l={request(){},unsubscribe(){}},c=0,b=!1,p=!1,f={request(m){if(!(b||p)){if(m<=0){e.onError(new Error(`request must be > 0, but was ${m}`));return}c=Math.min(c+m,Number.MAX_SAFE_INTEGER),l.request(m)}},unsubscribe(){b=!0,l.unsubscribe()}},S=()=>{this.source.subscribe({onSubscribe(m){l=m,c>0&&m.request(c)},onNext(m){!b&&!p&&e.onNext(m)},onError(m){!b&&!p&&u(m)},onComplete(){!b&&!p&&(p=!0,t?.onComplete(),e.onComplete())}})};return n(s).subscribe({onSubscribe(m){m.request(Number.MAX_SAFE_INTEGER)},onNext(m){!b&&!p&&(l.unsubscribe(),S())},onError(m){!b&&!p&&(p=!0,e.onError(m))},onComplete(){!b&&!p&&(p=!0,e.onComplete())}}),e.onSubscribe(f),S(),f}})}repeatWhen(n){return new a({subscribe:e=>{let r=[],t=null,o=0,u=!1,i=()=>{if(!u){u=!0;try{for(;!f&&!p&&o>0&&r.length>0&&t;)o--,t.onNext(r.shift())}finally{u=!1}}},s=()=>{r.push(void 0),i()},l=new a({subscribe(d){t=d;let E={request(N){o=Math.min(o+N,Number.MAX_SAFE_INTEGER),i()},unsubscribe(){t=null}};return d.onSubscribe(E),E}}),c={request(){},unsubscribe(){}},b=0,p=!1,f=!1,S={request(d){if(!(p||f)){if(d<=0){e.onError(new Error(`request must be > 0, but was ${d}`));return}b=Math.min(b+d,Number.MAX_SAFE_INTEGER),c.request(d)}},unsubscribe(){p=!0,c.unsubscribe()}},m=()=>{this.source.subscribe({onSubscribe(d){c=d,b>0&&d.request(b)},onNext(d){!p&&!f&&e.onNext(d)},onError(d){!p&&!f&&(f=!0,e.onError(d))},onComplete(){!p&&!f&&s()}})};return n(l).subscribe({onSubscribe(d){d.request(Number.MAX_SAFE_INTEGER)},onNext(d){!p&&!f&&(c.unsubscribe(),m())},onError(d){!p&&!f&&(f=!0,e.onError(d))},onComplete(){!p&&!f&&(f=!0,e.onComplete())}}),e.onSubscribe(S),m(),S}})}groupBy(n){return new a({subscribe:e=>{let r=new Map,t=!1,o={request(){},unsubscribe(){}},u={request(i){},unsubscribe(){t=!0,o.unsubscribe()}};return this.source.subscribe({onSubscribe(i){o=i,i.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(u)},onNext(i){if(t)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=r.get(s);l||(l=new w,r.set(s,l),e.onNext(Object.assign(a.from(l),{key:s}))),l.next(i)},onError(i){if(!t){for(let s of r.values())s.error(i);e.onError(i)}},onComplete(){if(!t){for(let i of r.values())i.complete();e.onComplete()}}}),u}})}bufferTimeout(n,e){return new a({subscribe:r=>{let t=[],o=null,u=!1,i=()=>{if(o!==null&&(clearTimeout(o),o=null),t.length>0&&!u){let b=t;t=[],r.onNext(b)}},s=()=>{o!==null&&clearTimeout(o),o=setTimeout(()=>{u||i()},e)},l=this.source.subscribe({onSubscribe(b){b.request(Number.MAX_SAFE_INTEGER)},onNext(b){u||(t.push(b),t.length>=n?i():s())},onError(b){u||(o!==null&&clearTimeout(o),r.onError(b))},onComplete(){u||(o!==null&&(clearTimeout(o),o=null),t.length>0&&r.onNext(t),r.onComplete())}}),c={request(b){l.request(b)},unsubscribe(){u=!0,o!==null&&clearTimeout(o),l.unsubscribe()}};return r.onSubscribe(c),c}})}sample(n){return new a({subscribe:e=>{let r,t=!1,o=!1,u={request(){},unsubscribe(){}},i={request(){},unsubscribe(){}},s={request(l){o||u.request(l)},unsubscribe(){o=!0,u.unsubscribe(),i.unsubscribe()}};return i=n.subscribe({onSubscribe(l){i=l,l.request(Number.MAX_SAFE_INTEGER)},onNext(l){if(o||!t)return;let c=r;t=!1,r=void 0,e.onNext(c)},onError(l){o||e.onError(l)},onComplete(){}}),this.source.subscribe({onSubscribe(l){u=l,e.onSubscribe(s)},onNext(l){o||(r=l,t=!0)},onError(l){o||e.onError(l)},onComplete(){o||e.onComplete()}}),s}})}delayUntil(n){return this.concatMap(e=>a.from({subscribe(r){let t=!1,o={request(){},unsubscribe(){}};return o=n(e).subscribe({onSubscribe(u){o=u,u.request(Number.MAX_SAFE_INTEGER)},onNext(u){t||(t=!0,o.unsubscribe(),r.onNext(e),r.onComplete())},onError(u){t||(t=!0,r.onError(u))},onComplete(){t||(t=!0,r.onNext(e),r.onComplete())}}),r.onSubscribe(o),o}}))}expand(n){return new a({subscribe:e=>{let r=[],t=!1,o=!1,u=!1,i=!1,s=0,l=p=>{i||(i=!0,p?e.onError(p):e.onComplete())},c=()=>{if(t||u||i)return;if(s<=0||r.length===0){o&&r.length===0&&l();return}t=!0;let p=r.shift();if(s--,e.onNext(p),u||i){t=!1;return}let f;try{f=n(p)}catch(S){t=!1,l(S instanceof Error?S:new Error(String(S)));return}f.subscribe({onSubscribe(S){S.request(Number.MAX_SAFE_INTEGER)},onNext(S){!u&&!i&&r.push(S)},onError(S){t=!1,l(S)},onComplete(){t=!1,c()}})},b={request(p){if(!(u||i)){if(p<=0){l(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){u=!0}};return this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(b)},onNext(p){!u&&!i&&(r.push(p),c())},onError(p){l(p)},onComplete(){o=!0,!t&&r.length===0&&l()}}),b}})}expandDeep(n){return new a({subscribe:e=>{let r=[],t=!1,o=!1,u=!1,i=!1,s=0,l=p=>{i||(i=!0,p?e.onError(p):e.onComplete())},c=()=>{if(t||u||i)return;if(s<=0||r.length===0){o&&r.length===0&&l();return}t=!0;let p=r.shift();if(s--,e.onNext(p),u||i){t=!1;return}let f;try{f=n(p)}catch(m){t=!1,l(m instanceof Error?m:new Error(String(m)));return}let S=[];f.subscribe({onSubscribe(m){m.request(Number.MAX_SAFE_INTEGER)},onNext(m){!u&&!i&&S.push(m)},onError(m){t=!1,l(m)},onComplete(){!u&&!i&&r.unshift(...S),t=!1,c()}})},b={request(p){if(!(u||i)){if(p<=0){l(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){u=!0}};return this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(b)},onNext(p){!u&&!i&&(r.push(p),c())},onError(p){l(p)},onComplete(){o=!0,!t&&r.length===0&&l()}}),b}})}elapsed(){return new a({subscribe:n=>{let e=Date.now(),r=this.source.subscribe({onSubscribe(t){e=Date.now()},onNext(t){let o=Date.now(),u=o-e;e=o,n.onNext([u,t])},onError(t){n.onError(t)},onComplete(){n.onComplete()}});return n.onSubscribe(r),r}})}timestamp(){return this.map(n=>[Date.now(),n])}materialize(){return new a({subscribe:n=>{let e=!1,r=this.source.subscribe({onSubscribe(t){},onNext(t){e||n.onNext(x.next(t))},onError(t){e||(e=!0,n.onNext(x.error(t)),n.onComplete())},onComplete(){e||(e=!0,n.onNext(x.complete()),n.onComplete())}});return n.onSubscribe(r),r}})}dematerialize(){return new a({subscribe:n=>{let e=!1,r=this.source.subscribe({onSubscribe(t){},onNext(t){e||(t.kind==="next"?n.onNext(t.value):t.kind==="error"?(e=!0,n.onError(t.error)):(e=!0,n.onComplete()))},onError(t){e||(e=!0,n.onError(t))},onComplete(){e||(e=!0,n.onComplete())}});return n.onSubscribe(r),r}})}onBackpressureBuffer(n=Number.MAX_SAFE_INTEGER){return new a({subscribe:e=>{let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=()=>{if(!(s||o)){s=!0;try{for(;t>0&&r.length>0&&!o;)t--,e.onNext(r.shift());u&&r.length===0&&!o&&(i?e.onError(i):e.onComplete())}finally{s=!1}}},c=this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER)},onNext(p){if(!o){if(r.length>=n){e.onError(new Error(`onBackpressureBuffer overflow (maxSize=${n})`));return}r.push(p),l()}},onError(p){o||(u=!0,i=p,l())},onComplete(){o||(u=!0,l())}}),b={request(p){if(!(o||u&&r.length===0)){if(p<=0){e.onError(new Error(`request must be > 0, but was ${p}`));return}t=Math.min(t+p,Number.MAX_SAFE_INTEGER),l()}},unsubscribe(){o=!0,r.length=0,c.unsubscribe()}};return e.onSubscribe(b),b}})}onBackpressureDrop(n){return new a({subscribe:e=>{let r=0,t=!1,o=this.source.subscribe({onSubscribe(i){i.request(Number.MAX_SAFE_INTEGER)},onNext(i){if(!t)if(r>0)r--,e.onNext(i);else try{n?.(i)}catch{}},onError(i){t||e.onError(i)},onComplete(){t||e.onComplete()}}),u={request(i){if(!t){if(i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}r=Math.min(r+i,Number.MAX_SAFE_INTEGER)}},unsubscribe(){t=!0,o.unsubscribe()}};return e.onSubscribe(u),u}})}onBackpressureLatest(){return new a({subscribe:n=>{let e,r=!1,t=0,o=!1,u=!1,i=null,s=()=>{if(!o){if(t>0&&r){t--;let b=e;r=!1,e=void 0,n.onNext(b)}u&&!r&&!o&&(i?n.onError(i):n.onComplete())}},l=this.source.subscribe({onSubscribe(b){b.request(Number.MAX_SAFE_INTEGER)},onNext(b){o||(e=b,r=!0,s())},onError(b){o||(u=!0,i=b,s())},onComplete(){o||(u=!0,s())}}),c={request(b){if(!(o||u&&!r)){if(b<=0){n.onError(new Error(`request must be > 0, but was ${b}`));return}t=Math.min(t+b,Number.MAX_SAFE_INTEGER),s()}},unsubscribe(){o=!0,l.unsubscribe()}};return n.onSubscribe(c),c}})}limitRate(n){return new a({subscribe:e=>{let r=Math.max(1,n),t=Math.max(1,Math.floor(r*.75)),o,u=0,i=0,s=!1,l=()=>{let b=r-u;b>0&&(u+=b,o.request(b))},c={request(b){if(!s){if(b<=0){e.onError(new Error(`request must be > 0, but was ${b}`));return}l()}},unsubscribe(){s=!0,o?.unsubscribe()}};return this.source.subscribe({onSubscribe(b){o=b,e.onSubscribe(c)},onNext(b){s||(u=Math.max(0,u-1),i++,e.onNext(b),i>=t&&(i=0,l()))},onError(b){s||e.onError(b)},onComplete(){s||e.onComplete()}}),c}})}ofType(n){return this.filter(e=>e instanceof n).cast()}transformDeferred(n){return a.defer(()=>a.from(n(this)))}};var h=class a extends R{constructor(n){super(n)}defaultDemand(){return 1}wrapSource(n){return new a(n)}static generate(n){return new a({subscribe(e){let r=!1,t=!1,o=!1,u=null,i=null,s=()=>{if(!(r||!t))if(u!==null){let b=u.value;u=null,e.onNext(b),r||e.onComplete()}else if(i!==null){let b=i;i=null,e.onError(b)}else o&&e.onComplete()},l={next(b){o||r||(o=!0,t?(e.onNext(b),r||e.onComplete()):u={value:b})},error(b){o||r||(o=!0,t?e.onError(b):i=b)},complete(){o||r||(o=!0,t&&e.onComplete())}};try{n(l)}catch(b){o||(o=!0,i=b instanceof Error?b:new Error(String(b)))}let c={request(b){if(!(r||t)){if(b<=0){e.onError(new Error(`request must be > 0, but was ${b}`));return}t=!0,s()}},unsubscribe(){r=!0}};return e.onSubscribe(c),c}})}static from(n){return new a(n)}static just(n){return a.generate(e=>e.next(n))}static justOrEmpty(n){return n!=null?a.just(n):a.empty()}static empty(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),n.onComplete(),e}})}static error(n){let e=n instanceof Error?n:new Error(String(n));return new a({subscribe(r){let t={request(){},unsubscribe(){}};return r.onSubscribe(t),r.onError(e),t}})}static fromPromise(n){return a.generate(e=>n.then(r=>e.next(r)).catch(r=>e.error(r instanceof Error?r:new Error(String(r)))))}static defer(n){return new a({subscribe(e){return n().subscribe(e)}})}static create(n){return a.generate(n)}static delay(n){return a.generate(e=>{let r=setTimeout(()=>e.next(0),n)})}static fromCallable(n){return a.generate(e=>{try{e.next(n())}catch(r){e.error(r instanceof Error?r:new Error(String(r)))}})}static firstWithValue(...n){return n.length===0?a.empty():a.generate(e=>{let r=!1,t=0,o=[];for(let u of n){let i=u.subscribe({onSubscribe(s){},onNext(s){if(!r){r=!0;for(let l of o)l.unsubscribe();e.next(s)}},onError(s){if(!r){r=!0;for(let l of o)l.unsubscribe();e.error(s)}},onComplete(){r||(t++,t===n.length&&(r=!0,e.complete()))}});o.push(i)}for(let u of o)u.request(1)})}map(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{e.onNext(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}mapNotNull(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(!r)try{let u=n(o);u!=null?e.onNext(u):(r=!0,e.onComplete())}catch(u){r=!0,e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onComplete())}});return e.onSubscribe(t),t}})}flatMap(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t&&t.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}}),u>0&&t.request(u)},onError(s){e.onError(s)},onComplete(){t||e.onComplete()}}),r.request(1),i}})}filter(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(!r)try{n(o)?e.onNext(o):(r=!0,e.onComplete())}catch(u){r=!0,e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onComplete())}});return e.onSubscribe(t),t}})}filterWhen(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u={request(i){if(!o&&i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){if(o)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=!1;t=s.subscribe({onSubscribe(c){},onNext(c){l||(l=!0,c?e.onNext(i):e.onComplete())},onError(c){l||(l=!0,e.onError(c))},onComplete(){l||(l=!0,e.onComplete())}}),t.request(1)},onError(i){e.onError(i)},onComplete(){t||e.onComplete()}}),r.request(1),u}})}cast(){return new a(this.source)}doFinally(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n()}catch{}e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}pipe(n,e,r){return new a({subscribe:t=>{n(u=>t.onNext(u),u=>t.onError(u),()=>t.onComplete());let o={request:e,unsubscribe:r};return t.onSubscribe(o),o}})}flatMapMany(n){return C.from({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t&&t.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}}),u>0&&t.request(u)},onError(s){e.onError(s)},onComplete(){t||e.onComplete()}}),r.request(1),i}})}zipWith(n){return a.generate(e=>{let r,t,o=!1,u=!1,i=!1,s=p=>{i||(i=!0,c?.unsubscribe(),b?.unsubscribe(),e.error(p))},l=()=>{o&&u&&e.next([r,t])},c,b;c=this.source.subscribe({onSubscribe(p){},onNext(p){r=p,o=!0,l()},onError(p){s(p)},onComplete(){o||(b?.unsubscribe(),e.complete())}}),b=n.subscribe({onSubscribe(p){},onNext(p){t=p,u=!0,l()},onError(p){s(p)},onComplete(){u||(c?.unsubscribe(),e.complete())}}),c.request(1),b.request(1)})}zipWhen(n){return a.generate(e=>{this.source.subscribe({onSubscribe(t){},onNext(t){let o;try{o=n(t)}catch(i){e.error(i instanceof Error?i:new Error(String(i)));return}o.subscribe({onSubscribe(i){},onNext(i){e.next([t,i])},onError(i){e.error(i)},onComplete(){e.complete()}}).request(1)},onError(t){e.error(t)},onComplete(){e.complete()}}).request(1)})}hasElement(){return a.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(!0)},onError(r){n.error(r)},onComplete(){n.next(!1)}});e.request(1)})}doOnSuccess(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)}catch(o){e.onError(o instanceof Error?o:new Error(String(o)));return}e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}onErrorComplete(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){!n||n(t)?e.onComplete():e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}thenReturn(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onNext(n),e.onComplete())}});return e.onSubscribe(t),t}})}delayElement(n){return new a({subscribe:e=>{let r=null,t=!1,o=this.source.subscribe({onSubscribe(i){},onNext(i){t||(r=setTimeout(()=>{t||(e.onNext(i),e.onComplete())},n))},onError(i){e.onError(i)},onComplete(){}}),u={request(i){o.request(i)},unsubscribe(){t=!0,r!==null&&clearTimeout(r),o.unsubscribe()}};return e.onSubscribe(u),u}})}delayUntil(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u={request(i){o||r.request(i)},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){if(o)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=!1;t=s.subscribe({onSubscribe(c){},onNext(c){l||o||(l=!0,t?.unsubscribe(),e.onNext(i),e.onComplete())},onError(c){o||e.onError(c)},onComplete(){!l&&!o&&(l=!0,e.onNext(i),e.onComplete())}}),t.request(Number.MAX_SAFE_INTEGER)},onError(i){o||e.onError(i)},onComplete(){!o&&!t&&e.onComplete()}}),u}})}or(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=!1,i={request(s){o||(t?t.request(s):r.request(s))},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){o||(u=!0,e.onNext(s))},onError(s){o||e.onError(s)},onComplete(){o||u||(t=n.subscribe({onSubscribe(s){},onNext(s){o||e.onNext(s)},onError(s){o||e.onError(s)},onComplete(){o||e.onComplete()}}),t.request(1))}}),i}})}retryWhen(n){return new a({subscribe:e=>{let r=!1,t=null,o=!1,u=null,i=C.from({subscribe(f){u={onNext:m=>f.onNext(m)};let S={request(m){},unsubscribe(){r=!0}};return f.onSubscribe(S),S}}),s=n(i),l,c=()=>{r||o||(t=this.source.subscribe({onSubscribe(f){},onNext(f){r||o||(o=!0,e.onNext(f),e.onComplete())},onError(f){r||u?.onNext(f)},onComplete(){!r&&!o&&e.onComplete()}}),t.request(1))},b=s.subscribe({onSubscribe(f){},onNext(f){!r&&!o&&c()},onError(f){r||e.onError(f)},onComplete(){!r&&!o&&e.onComplete()}});b.request(Number.MAX_SAFE_INTEGER),l={onNext:f=>{!r&&!o&&c()},onError:f=>{r||e.onError(f)},onComplete:()=>{!r&&!o&&e.onComplete()}},c();let p={request(f){},unsubscribe(){r=!0,t?.unsubscribe(),b.unsubscribe()}};return e.onSubscribe(p),p}})}toFuture(){return this.toPromise()}toPromise(){return new Promise((n,e)=>{let r=null;this.subscribe({onSubscribe(o){},onNext(o){r=o},onError(o){e(o)},onComplete(){n(r)}}).request(Number.MAX_SAFE_INTEGER)})}};var g=class{constructor(){this.pendingValue=null;this.completed=!1;this.terminalError=null;this.entries=new Map}get terminated(){return this.completed||this.terminalError!==null}next(n){this.terminated||this.pendingValue!==null||(this.pendingValue={value:n})}error(n){if(!this.terminated){this.terminalError=n;for(let[e,r]of this.entries)r.cancelled||e.onError(n);this.entries.clear()}}complete(){if(!this.terminated){this.completed=!0;for(let[n,e]of this.entries)e.cancelled||(this.pendingValue===null?(n.onComplete(),this.entries.delete(n)):e.demand>=1?(e.demand--,n.onNext(this.pendingValue.value),e.cancelled||n.onComplete(),this.entries.delete(n)):e.completionQueued=!0)}}subscribe(n){if(this.terminalError){let t={request(){},unsubscribe(){}};return n.onSubscribe(t),n.onError(this.terminalError),t}let e={demand:0,cancelled:!1,completionQueued:this.completed};if(this.entries.set(n,e),this.completed&&this.pendingValue===null){this.entries.delete(n);let t={request(){},unsubscribe(){}};return n.onSubscribe(t),n.onComplete(),t}let r={request:t=>{if(!e.cancelled){if(t<=0){e.cancelled=!0,this.entries.delete(n),n.onError(new Error(`request must be > 0, but was ${t}`));return}e.demand=Math.min(e.demand+t,Number.MAX_SAFE_INTEGER),e.completionQueued&&this.pendingValue!==null&&e.demand>=1&&(e.demand--,e.cancelled=!0,this.entries.delete(n),n.onNext(this.pendingValue.value),n.onComplete())}},unsubscribe:()=>{e.cancelled=!0,this.entries.delete(n)}};return n.onSubscribe(r),r}};var v=class{constructor(){this.terminal=null;this.subscribers=new Set}next(n){}error(n){if(!this.terminal){this.terminal={kind:"error",error:n};for(let e of this.subscribers)e.onError(n);this.subscribers.clear()}}complete(){if(!this.terminal){this.terminal={kind:"completed"};for(let n of this.subscribers)n.onComplete();this.subscribers.clear()}}subscribe(n){if(this.terminal){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),this.terminal.kind==="completed"?n.onComplete():n.onError(this.terminal.error),r}this.subscribers.add(n);let e={request:r=>{this.subscribers.has(n)&&r<=0&&(this.subscribers.delete(n),n.onError(new Error(`request must be > 0, but was ${r}`)))},unsubscribe:()=>{this.subscribers.delete(n)}};return n.onSubscribe(e),e}};var q=class{constructor(){this.subscriber=null;this.demand=0;this.cancelled=!1;this.terminated=!1;this.terminalError=null}shouldReplayTerminalOnSubscribe(){return this.terminated}onDemandGranted(){}onUnsubscribed(){}afterSubscribed(){}onTerminal(){this.subscriber&&!this.cancelled&&(this.terminalError?this.subscriber.onError(this.terminalError):this.subscriber.onComplete())}error(n){this.terminated||(this.terminated=!0,this.terminalError=n,this.onTerminal())}complete(){this.terminated||(this.terminated=!0,this.onTerminal())}subscribe(n){if(this.subscriber!==null){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),n.onError(new Error(`${this.constructor.name} allows only one subscriber`)),r}if(this.shouldReplayTerminalOnSubscribe()){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),this.terminalError?n.onError(this.terminalError):n.onComplete(),r}this.subscriber=n;let e={request:r=>{if(!this.cancelled){if(r<=0){this.cancelled=!0;let t=this.subscriber;this.subscriber=null,t?.onError(new Error(`request must be > 0, but was ${r}`));return}this.demand=Math.min(this.demand+r,Number.MAX_SAFE_INTEGER),this.onDemandGranted()}},unsubscribe:()=>{this.cancelled=!0,this.subscriber=null,this.onUnsubscribed()}};return n.onSubscribe(e),this.afterSubscribed(),e}};var M=class extends q{constructor(){super(...arguments);this.buffer=[];this.draining=!1}shouldReplayTerminalOnSubscribe(){return!1}onTerminal(){this.drain()}onDemandGranted(){this.drain()}onUnsubscribed(){this.buffer.length=0}afterSubscribed(){this.drain()}next(e){this.terminated||this.cancelled||(this.buffer.push(e),this.drain())}drain(){if(!(!this.subscriber||this.cancelled||this.draining)){this.draining=!0;try{for(;this.demand>0&&this.buffer.length>0;)if(this.demand--,this.subscriber.onNext(this.buffer.shift()),this.cancelled)return;if(this.buffer.length===0&&this.terminated){let e=this.subscriber;this.subscriber=null,this.terminalError?e.onError(this.terminalError):e.onComplete()}}finally{this.draining=!1}}}};var A=class extends q{next(n){if(!(this.terminated||this.cancelled||!this.subscriber)){if(this.demand<=0){this.error(new Error("UnicastOnBackpressureErrorSink: subscriber cannot keep up with demand"));return}this.demand--,this.subscriber.onNext(n)}}};var F=class extends T{createEntry(){return{demand:0,cancelled:!1}}next(n){if(this.terminated)return;let e=[...this.entries.values()].filter(r=>!r.cancelled);if(!(e.length===0||!e.every(r=>r.demand>0)))for(let[r,t]of this.entries)t.cancelled||(t.demand--,r.onNext(n))}};var P=class extends T{createEntry(){return{demand:0,cancelled:!1}}next(n){if(!this.terminated)for(let[e,r]of this.entries)!r.cancelled&&r.demand>0&&(r.demand--,e.onNext(n))}};var _=class extends T{constructor(n=256,e=!0){super(),this.bufferSize=n,this.autoCancel=e}createEntry(){return{buffer:[],demand:0,cancelled:!1,draining:!1}}deliverComplete(n,e){this.drainEntry(n,e)}clearEntriesAfterComplete(){return!1}onDemandGranted(n,e){this.drainEntry(n,e)}onUnsubscribed(n,e){this.autoCancel&&this.entries.size===0&&(this.terminated=!0)}next(n){if(!this.terminated)for(let[e,r]of this.entries)r.cancelled||(r.demand>0?(r.demand--,e.onNext(n)):r.buffer.length<this.bufferSize?r.buffer.push(n):(r.cancelled=!0,this.entries.delete(e),e.onError(new Error("MulticastOnBackpressureBufferSink: buffer overflow")),this.autoCancel&&this.entries.size===0&&(this.terminated=!0)))}drainEntry(n,e){if(!(e.cancelled||e.draining)){e.draining=!0;try{for(;e.demand>0&&e.buffer.length>0;)if(e.demand--,n.onNext(e.buffer.shift()),e.cancelled)return;e.buffer.length===0&&this.terminated&&(this.entries.delete(n),this.terminalError?n.onError(this.terminalError):n.onComplete())}finally{e.draining=!1}}}};var y=class extends T{constructor(e){super();this.history=[];this.limit=e}createEntry(){return{replay:[...this.history],demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.history.length===0}deliverError(e,r){this.drainEntry(e,r),r.cancelled||e.onError(this.terminalError)}deliverComplete(e,r){r.cancelled||this.drainEntry(e,r)}clearEntriesAfterComplete(){return!1}onDemandGranted(e,r){this.drainEntry(e,r)}next(e){if(!this.terminated){this.history.push(e),this.history.length>this.limit&&this.history.shift();for(let[r,t]of this.entries)t.cancelled||(t.replay.push(e),this.drainEntry(r,t))}}drainEntry(e,r){if(!(r.cancelled||r.draining)){r.draining=!0;try{for(;r.demand>0&&r.replay.length>0;)if(r.demand--,e.onNext(r.replay.shift()),r.cancelled)return;r.replay.length===0&&this.terminated&&(this.entries.delete(e),this.terminalError?e.onError(this.terminalError):e.onComplete())}finally{r.draining=!1}}}};var k=class extends T{constructor(n){super(),this.latestValue=n}createEntry(){return{pending:this.latestValue,hasPending:!0,demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.terminalError!==null}deliverError(n,e){this.drainEntry(n,e),e.cancelled||n.onError(this.terminalError)}deliverComplete(n,e){e.cancelled||this.drainEntry(n,e)}clearEntriesAfterComplete(){return!1}onDemandGranted(n,e){this.drainEntry(n,e)}next(n){if(!this.terminated){this.latestValue=n;for(let[e,r]of this.entries)r.cancelled||(r.pending=n,r.hasPending=!0,this.drainEntry(e,r))}}drainEntry(n,e){if(!(e.cancelled||e.draining)){e.draining=!0;try{if(e.hasPending&&e.demand>0&&(e.demand--,e.hasPending=!1,n.onNext(e.pending),e.cancelled))return;!e.hasPending&&this.terminated&&(this.entries.delete(n),this.terminalError?n.onError(this.terminalError):n.onComplete())}finally{e.draining=!1}}}};var Z={empty:()=>new v,one:()=>new g,many:()=>({multicast:()=>({directAllOrNothing:()=>new F,directBestEffort:()=>new P,onBackpressureBuffer:(a=256,n=!0)=>new _(a,n)}),unicast:()=>({onBackpressureBuffer:()=>new M,onBackpressureError:()=>new A}),replay:()=>({all:()=>new w,latest:a=>new y(a),latestOrDefault:a=>new k(a),limit:a=>new y(a)})})};0&&(module.exports={Flux,Mono,Schedulers,Signal,Sinks});
|
|
1
|
+
"use strict";var O=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var j=(a,n)=>{for(var e in n)O(a,e,{get:n[e],enumerable:!0})},Q=(a,n,e,r)=>{if(n&&typeof n=="object"||typeof n=="function")for(let t of K(n))!L.call(a,t)&&t!==e&&O(a,t,{get:()=>n[t],enumerable:!(r=U(n,t))||r.enumerable});return a};var J=a=>Q(O({},"__esModule",{value:!0}),a);var H={};j(H,{Flux:()=>T,Mono:()=>h,Schedulers:()=>z,Signal:()=>N,Sinks:()=>Z});module.exports=J(H);var x=class{constructor(){this.entries=new Map;this.terminated=!1;this.terminalError=null}asFlux(){return T.from(this)}shouldReplayTerminalOnSubscribe(){return this.terminated}onDemandGranted(n,e){}onUnsubscribed(n,e){}onSubscribed(n,e){}deliverError(n,e){e.cancelled||n.onError(this.terminalError)}deliverComplete(n,e){e.cancelled||n.onComplete()}clearEntriesAfterComplete(){return!0}error(n){if(!this.terminated){this.terminated=!0,this.terminalError=n;for(let[e,r]of this.entries)this.deliverError(e,r);this.entries.clear()}}complete(){if(!this.terminated){this.terminated=!0;for(let[n,e]of this.entries)this.deliverComplete(n,e);this.clearEntriesAfterComplete()&&this.entries.clear()}}subscribe(n){if(this.shouldReplayTerminalOnSubscribe()){let t={request(){},unsubscribe(){}};return n.onSubscribe(t),this.terminalError?n.onError(this.terminalError):n.onComplete(),t}let e=this.createEntry();this.entries.set(n,e);let r={request:t=>{if(!e.cancelled){if(t<=0){e.cancelled=!0,this.entries.delete(n),n.onError(new Error(`request must be > 0, but was ${t}`));return}e.demand=Math.min(e.demand+t,Number.MAX_SAFE_INTEGER),this.onDemandGranted(n,e)}},unsubscribe:()=>{e.cancelled=!0,this.entries.delete(n),this.onUnsubscribed(n,e)}};return n.onSubscribe(r),this.onSubscribed(n,e),r}};var C=class extends x{constructor(){super(...arguments);this.history=[]}createEntry(){return{position:0,demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.history.length===0}deliverError(e,r){this.drainEntry(e,r),r.cancelled||e.onError(this.terminalError)}deliverComplete(e,r){r.cancelled||this.drainEntry(e,r)}clearEntriesAfterComplete(){return!1}onDemandGranted(e,r){this.drainEntry(e,r)}next(e){if(!this.terminated){this.history.push(e);for(let[r,t]of this.entries)t.cancelled||this.drainEntry(r,t)}}drainEntry(e,r){if(!(r.cancelled||r.draining)){r.draining=!0;try{for(;r.demand>0&&r.position<this.history.length;)if(r.demand--,e.onNext(this.history[r.position++]),r.cancelled)return;r.position>=this.history.length&&this.terminated&&(this.entries.delete(e),this.terminalError?e.onError(this.terminalError):e.onComplete())}finally{r.draining=!1}}}};var N={next(a){return{kind:"next",value:a}},error(a){return{kind:"error",error:a}},complete(){return{kind:"complete"}}};var R=class{constructor(n){this.source=n}subscribe(n,e,r){if(n!==void 0&&typeof n=="object")return this.source.subscribe(n);let t=n,o=this.defaultDemand();return this.source.subscribe({onSubscribe(u){u.request(o)},onNext:t??(()=>{}),onError:e??(u=>{throw u}),onComplete:r??(()=>{})})}switchIfEmpty(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=!1,i=0,s={request(l){if(!u){if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}i=Math.min(i+l,Number.MAX_SAFE_INTEGER),t?t.request(l):r.request(l)}},unsubscribe(){u=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(l){r=l,e.onSubscribe(s)},onNext(l){o=!0,e.onNext(l)},onError(l){e.onError(l)},onComplete(){if(o||u){e.onComplete();return}t=n.subscribe({onSubscribe(l){t=l,i>0&&t.request(i)},onNext(l){e.onNext(l)},onError(l){e.onError(l)},onComplete(){e.onComplete()}})}}),s}})}onErrorReturn(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){o||(t=n.subscribe({onSubscribe(l){t=l,u>0&&t.request(u)},onNext(l){e.onNext(l)},onError(l){e.onError(l)},onComplete(){e.onComplete()}}))},onComplete(){e.onComplete()}}),i}})}onErrorContinue(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){n(t)?e.onComplete():e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doFirst(n){return this.wrapSource({subscribe:e=>{let r=!0,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(r){r=!1;try{n()}catch{}}e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}doOnNext(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)}catch{}e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doOnError(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n(t)}catch{}e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}doOnSubscribe(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});try{n(r)}catch{}return e.onSubscribe(r),r}})}publishOn(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){n.schedule(()=>e.onNext(t))},onError(t){n.schedule(()=>e.onError(t))},onComplete(){n.schedule(()=>e.onComplete())}});return e.onSubscribe(r),r}})}onErrorResume(n){return this.wrapSource({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){t=c,u>0&&c.request(u)},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}})},onComplete(){e.onComplete()}}),i}})}onErrorMap(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{e.onError(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}timeout(n,e){return this.wrapSource({subscribe:r=>{let t={request(){},unsubscribe(){}},o=null,u=!1,i=!1,s=!1,l=0,c=null,b=()=>{c!==null&&(clearTimeout(c),c=null)},p=()=>{b(),c=setTimeout(()=>{u||s||(i=!0,t.unsubscribe(),e?o=e.subscribe({onSubscribe(S){o=S,l>0&&S.request(l)},onNext(S){!u&&!s&&r.onNext(S)},onError(S){!u&&!s&&(s=!0,r.onError(S))},onComplete(){!u&&!s&&(s=!0,r.onComplete())}}):(s=!0,r.onError(new Error(`TimeoutError: no item within ${n}ms`))))},n)},f={request(S){if(!(u||s)){if(S<=0){r.onError(new Error(`request must be > 0, but was ${S}`));return}l=Math.min(l+S,Number.MAX_SAFE_INTEGER),o?o.request(S):t.request(S)}},unsubscribe(){u=!0,b(),t.unsubscribe(),o?.unsubscribe()}};return this.source.subscribe({onSubscribe(S){t=S,r.onSubscribe(f),p()},onNext(S){u||i||(p(),r.onNext(S))},onError(S){b(),!u&&!s&&(s=!0,r.onError(S))},onComplete(){b(),!u&&!s&&(s=!0,r.onComplete())}}),f}})}delaySubscription(n){return this.wrapSource({subscribe:e=>{let r=null,t=!1,o=0,u={request(l){if(!t){if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}o=Math.min(o+l,Number.MAX_SAFE_INTEGER),r&&r.request(l)}},unsubscribe(){t=!0,r?.unsubscribe()}};e.onSubscribe(u);let i=setTimeout(()=>{t||this.source.subscribe({onSubscribe(l){r=l,o>0&&l.request(o)},onNext(l){t||e.onNext(l)},onError(l){t||e.onError(l)},onComplete(){t||e.onComplete()}})},n),s=u.unsubscribe.bind(u);return u.unsubscribe=()=>{clearTimeout(i),s()},u}})}log(n="reactor"){return this.wrapSource({subscribe:e=>{let r=`[${n}]`,t;return this.source.subscribe({onSubscribe(o){console.log(`${r} onSubscribe`),t={request(u){console.log(`${r} request(${u})`),o.request(u)},unsubscribe(){console.log(`${r} cancel`),o.unsubscribe()}},e.onSubscribe(t)},onNext(o){console.log(`${r} onNext(${JSON.stringify(o)})`),e.onNext(o)},onError(o){console.error(`${r} onError: ${o.message}`),e.onError(o)},onComplete(){console.log(`${r} onComplete`),e.onComplete()}}),t}})}doOnRequest(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}}),t={request(o){try{n(o)}catch{}r.request(o)},unsubscribe(){r.unsubscribe()}};return e.onSubscribe(t),t}})}doOnEach(n){return this.wrapSource({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(N.next(t))}catch{}e.onNext(t)},onError(t){try{n(N.error(t))}catch{}e.onError(t)},onComplete(){try{n(N.complete())}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}subscribeOn(n){return this.wrapSource({subscribe:e=>{let r=null,t=0,o=!1,u={request(i){if(!o){if(i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}r?r.request(i):t=Math.min(t+i,Number.MAX_SAFE_INTEGER)}},unsubscribe(){o=!0,r?.unsubscribe()}};return e.onSubscribe(u),n.schedule(()=>{o||(r=this.source.subscribe({onSubscribe(i){},onNext(i){e.onNext(i)},onError(i){e.onError(i)},onComplete(){e.onComplete()}}),t>0&&r.request(t))}),u}})}};var I=class{schedule(n){n()}};var X=class{schedule(n){Promise.resolve().then(n)}};var $=class{schedule(n){setTimeout(n,0)}};var D=class{constructor(n){this.delay=n}schedule(n){let e=setTimeout(n,this.delay);return{cancel:()=>clearTimeout(e)}}};var B=class{constructor(n){this.interval=n}schedule(n){let e=setInterval(n,this.interval);return{cancel:()=>clearInterval(e)}}};var z={immediate:()=>new I,micro:()=>new X,macro:()=>new $,delay:a=>new D(a),interval:a=>new B(a)};var T=class a extends R{constructor(n){super(n)}defaultDemand(){return Number.MAX_SAFE_INTEGER}wrapSource(n){return new a(n)}static from(n){return new a(n)}static generate(n){return new a({subscribe(e){let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=!1,c=()=>{if(!(l||s)){l=!0;try{for(;t>0&&r.length>0;)if(t--,e.onNext(r.shift()),s)return;!u&&r.length===0&&o&&(u=!0,i?e.onError(i):e.onComplete())}finally{l=!1}}},b={next(f){o||s||(t>0?(t--,e.onNext(f)):r.push(f))},error(f){o||s||(o=!0,i=f,c())},complete(){o||s||(o=!0,c())}},p={request(f){if(!s){if(f<=0){e.onError(new Error(`request must be > 0, but was ${f}`));return}t=Math.min(t+f,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){s=!0,r.length=0}};e.onSubscribe(p);try{n(b)}catch(f){o||(o=!0,i=f instanceof Error?f:new Error(String(f)),c())}return p}})}static fromIterable(n){return a.generate(e=>{for(let r of n)e.next(r);e.complete()})}static range(n,e){return a.generate(r=>{for(let t=0;t<e;t++)r.next(n+t);r.complete()})}static empty(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),n.onComplete(),e}})}static defer(n){return new a({subscribe(e){return n().subscribe(e)}})}static just(...n){return a.fromIterable(n)}static error(n){return new a({subscribe(e){let r={request(){},unsubscribe(){}};return e.onSubscribe(r),e.onError(n),r}})}static never(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),e}})}static create(n){return new a({subscribe(e){let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=[],c=[],b=[],p=()=>{for(let d of b)try{d()}catch{}},f=()=>{if(!(s||o)){s=!0;try{for(;t>0&&r.length>0&&!o;)t--,e.onNext(r.shift());u&&r.length===0&&!o&&(i?e.onError(i):e.onComplete())}finally{s=!1}}},S={next(d){o||u||(r.push(d),f())},error(d){o||u||(u=!0,i=d,p(),f())},complete(){o||u||(u=!0,p(),f())},get requested(){return t},onRequest(d){return l.push(d),S},onCancel(d){return c.push(d),S},onDispose(d){return b.push(d),S}},m={request(d){if(!(o||u&&r.length===0)){if(d<=0){e.onError(new Error(`request must be > 0, but was ${d}`));return}t=Math.min(t+d,Number.MAX_SAFE_INTEGER);for(let E of l)try{E(d)}catch{}f()}},unsubscribe(){if(!o){o=!0,r.length=0;for(let d of c)try{d()}catch{}p()}}};e.onSubscribe(m);try{n(S)}catch(d){!u&&!o&&S.error(d instanceof Error?d:new Error(String(d)))}return m}})}static using(n,e,r){return a.defer(()=>{let t=n();return a.from(e(t)).doFinally(()=>{try{r(t)}catch{}})})}static merge(...n){return n.length===0?a.empty():n.length===1?a.from(n[0]):new a({subscribe(e){let r=n.length,t=0,o=!1,u=!1,i=new Array(r),s=c=>{if(!u){u=!0;for(let b of i)b?.unsubscribe();c?e.onError(c):e.onComplete()}},l={request(c){if(!(o||u)){if(c<=0){s(new Error(`request must be > 0, but was ${c}`));return}for(let b of i)b.request(c)}},unsubscribe(){o=!0;for(let c of i)c?.unsubscribe()}};for(let c=0;c<r;c++){let b;n[c].subscribe({onSubscribe(p){b=p},onNext(p){!o&&!u&&e.onNext(p)},onError(p){s(p)},onComplete(){++t===r&&s()}}),i[c]=b}return e.onSubscribe(l),l}})}static firstWithValue(...n){return new a({subscribe(e){if(n.length===0){let c={request(){},unsubscribe(){}};return e.onSubscribe(c),e.onComplete(),c}let r=n.length,t=!1,o=!1,u=0,i=null,s=new Array(r),l={request(c){if(!o)for(let b of s)b.request(c)},unsubscribe(){o=!0;for(let c of s)c?.unsubscribe()}};for(let c=0;c<r;c++){let b=c,p;n[b].subscribe({onSubscribe(f){p=f},onNext(f){if(!(o||t)){t=!0;for(let S=0;S<r;S++)S!==b&&s[S]?.unsubscribe();e.onNext(f),e.onComplete()}},onError(f){o||t||(i=f,++u===r&&e.onError(i))},onComplete(){o||t||++u===r&&e.onComplete()}}),s[b]=p}return e.onSubscribe(l),l}})}static interval(n){return new a({subscribe(e){let r=0,t=0,o=!1,u=setInterval(()=>{o||r>0&&(r--,e.onNext(t++))},n),i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}r=Math.min(r+s,Number.MAX_SAFE_INTEGER)}},unsubscribe(){o=!0,clearInterval(u)}};return e.onSubscribe(i),i}})}static zip(n,e){return n.length===0?a.empty():new a({subscribe(r){let t=n.length,o=0,u=!1,i=!1,s=Array.from({length:t},()=>[]),l=new Array(t).fill(!1),c=new Array(t),b=()=>{for(;!u&&!i&&o>0&&s.every(f=>f.length>0);){o--;let f=s.map(m=>m.shift()),S;try{S=e(...f)}catch(m){i=!0;for(let d of c)d?.unsubscribe();r.onError(m instanceof Error?m:new Error(String(m)));return}r.onNext(S);for(let m=0;m<t;m++)l[m]||c[m].request(1)}if(!i&&l.some((f,S)=>f&&s[S].length===0)){i=!0;for(let f of c)f?.unsubscribe();r.onComplete()}},p={request(f){if(!(u||i)){if(f<=0){r.onError(new Error(`request must be > 0, but was ${f}`));return}o=Math.min(o+f,Number.MAX_SAFE_INTEGER),b()}},unsubscribe(){u=!0;for(let f of c)f?.unsubscribe()}};for(let f=0;f<t;f++){let S=f,m;n[S].subscribe({onSubscribe(d){m=d},onNext(d){u||i||(s[S].push(d),b())},onError(d){if(!(u||i)){i=!0;for(let E of c)E?.unsubscribe();r.onError(d)}},onComplete(){u||i||(l[S]=!0,b())}}),c[S]=m}r.onSubscribe(p);for(let f=0;f<t;f++)c[f].request(1);return p}})}static combineLatest(n,e){return n.length===0?a.empty():new a({subscribe(r){let t=n.length,o=0,u=!1,i=!1,s=[],l=new Array(t).fill(void 0),c=new Array(t).fill(!1),b=new Array(t).fill(!1),p=new Array(t),f=()=>{for(;!u&&!i&&o>0&&s.length>0;)o--,r.onNext(s.shift());!i&&b.every(Boolean)&&s.length===0&&(i=!0,r.onComplete())},S={request(m){if(!(u||i)){if(m<=0){r.onError(new Error(`request must be > 0, but was ${m}`));return}o=Math.min(o+m,Number.MAX_SAFE_INTEGER),f()}},unsubscribe(){u=!0;for(let m of p)m?.unsubscribe()}};for(let m=0;m<t;m++){let d=m,E;n[d].subscribe({onSubscribe(w){E=w},onNext(w){if(!(u||i)&&(l[d]=w,c[d]=!0,c.every(Boolean))){let G;try{G=e(...l)}catch(V){i=!0;for(let W of p)W?.unsubscribe();r.onError(V instanceof Error?V:new Error(String(V)));return}s.push(G),f()}},onError(w){if(!(u||i)){i=!0;for(let G of p)G?.unsubscribe();r.onError(w)}},onComplete(){u||i||(b[d]=!0,f())}}),p[d]=E}r.onSubscribe(S);for(let m=0;m<t;m++)p[m].request(Number.MAX_SAFE_INTEGER);return S}})}map(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{e.onNext(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}mapNotNull(n){return new a({subscribe:e=>{let r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){try{let u=n(o);u!=null?e.onNext(u):r.request(1)}catch(u){e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}handle(n){return new a({subscribe:e=>{let r,t=!1,o=this.source.subscribe({onSubscribe(u){r=u},onNext(u){if(t)return;let i=!1,s={next(l){!i&&!t&&(i=!0,e.onNext(l))},error(l){t||(t=!0,e.onError(l))},complete(){t||(t=!0,e.onComplete())}};try{n(u,s)}catch(l){t||(t=!0,e.onError(l instanceof Error?l:new Error(String(l))))}!t&&!i&&r.request(1)},onError(u){t||e.onError(u)},onComplete(){t||e.onComplete()}});return e.onSubscribe(o),o}})}flatMap(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=new Set,o=!1,u=!1,i=!1,s=0,l=b=>{if(!u){u=!0,r.unsubscribe();for(let p of t)p.unsubscribe();t.clear(),b?e.onError(b):e.onComplete()}},c={request(b){if(!(o||u)){if(b<=0){l(new Error(`request must be > 0, but was ${b}`));return}s=Math.min(s+b,Number.MAX_SAFE_INTEGER);for(let p of t)p.request(b)}},unsubscribe(){o=!0,r.unsubscribe();for(let b of t)b.unsubscribe();t.clear()}};return this.source.subscribe({onSubscribe(b){r=b,e.onSubscribe(c)},onNext(b){if(o||u)return;let p;try{p=n(b)}catch(S){l(S instanceof Error?S:new Error(String(S)));return}let f=p.subscribe({onSubscribe(S){},onNext(S){!o&&!u&&e.onNext(S)},onError(S){l(S)},onComplete(){t.delete(f),!u&&i&&t.size===0&&l()}});t.add(f),s>0&&f.request(s)},onError(b){l(b)},onComplete(){i=!0,!u&&t.size===0&&l()}}),r.request(Number.MAX_SAFE_INTEGER),c}})}concatMap(n){return new a({subscribe:e=>{let r,t=null,o=!1,u=!1,i=!1,s=c=>{u||(u=!0,r?.unsubscribe(),t?.unsubscribe(),t=null,c?e.onError(c):e.onComplete())},l={request(c){if(!(o||u)){if(c<=0){s(new Error(`request must be > 0, but was ${c}`));return}t?t.request(c):r.request(1)}},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(c){r=c,e.onSubscribe(l)},onNext(c){if(o||u)return;let b;try{b=n(c)}catch(p){s(p instanceof Error?p:new Error(String(p)));return}b.subscribe({onSubscribe(p){t=p,p.request(Number.MAX_SAFE_INTEGER)},onNext(p){!o&&!u&&e.onNext(p)},onError(p){s(p)},onComplete(){o||u||(t=null,i?s():r.request(1))}})},onError(c){s(c)},onComplete(){i=!0,t===null&&s()}}),l}})}switchMap(n){return new a({subscribe:e=>{let r,t=null,o=!1,u=!1,i=!1,s=0,l=0,c=p=>{u||(u=!0,r?.unsubscribe(),t?.unsubscribe(),t=null,p?e.onError(p):e.onComplete())},b={request(p){if(!(o||u)){if(p<=0){c(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),t&&t.request(p)}},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(p){r=p,e.onSubscribe(b)},onNext(p){if(o||u)return;t?.unsubscribe(),t=null;let f=++l,S;try{S=n(p)}catch(m){c(m instanceof Error?m:new Error(String(m)));return}S.subscribe({onSubscribe(m){if(l!==f||o||u){m.unsubscribe();return}t=m,s>0&&m.request(s)},onNext(m){l===f&&!o&&!u&&e.onNext(m)},onError(m){l===f&&c(m)},onComplete(){l!==f||o||u||(t=null,i&&c())}})},onError(p){c(p)},onComplete(){i=!0,t===null&&c()}}),r.request(Number.MAX_SAFE_INTEGER),b}})}filter(n){return new a({subscribe:e=>{let r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){try{n(o)?e.onNext(o):r.request(1)}catch(u){e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){e.onError(o)},onComplete(){e.onComplete()}});return e.onSubscribe(t),t}})}filterWhen(n){return this.concatMap(e=>a.from(n(e)).filter(r=>r).map(()=>e))}cast(){return new a(this.source)}take(n){return n<=0?a.empty():new a({subscribe:e=>{let r,t=0,o=!1,u={request(i){o||r?.request(i)},unsubscribe(){o=!0,r?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){o||(e.onNext(i),++t>=n&&(o=!0,r.unsubscribe(),e.onComplete()))},onError(i){o||e.onError(i)},onComplete(){o||e.onComplete()}}),u}})}takeWhile(n){return new a({subscribe:e=>{let r,t=!1,o={request(u){t||r?.request(u)},unsubscribe(){t=!0,r?.unsubscribe()}};return this.source.subscribe({onSubscribe(u){r=u,e.onSubscribe(o)},onNext(u){if(!t)try{n(u)?e.onNext(u):(t=!0,r.unsubscribe(),e.onComplete())}catch(i){t=!0,e.onError(i instanceof Error?i:new Error(String(i)))}},onError(u){t||e.onError(u)},onComplete(){t||e.onComplete()}}),o}})}takeUntilOther(n){return new a({subscribe:e=>{let r,t,o=!1,u={request(i){o||r?.request(i)},unsubscribe(){o=!0,r?.unsubscribe(),t?.unsubscribe()}};return t=n.subscribe({onSubscribe(i){t=i,i.request(1)},onNext(i){o||(o=!0,r?.unsubscribe(),e.onComplete())},onError(i){o||(o=!0,e.onError(i))},onComplete(){}}),this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){o||e.onNext(i)},onError(i){o||e.onError(i)},onComplete(){o||(o=!0,t?.unsubscribe(),e.onComplete())}}),u}})}defaultIfEmpty(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){r=!0,e.onNext(o)},onError(o){e.onError(o)},onComplete(){r||e.onNext(n),e.onComplete()}});return e.onSubscribe(t),t}})}retry(n=Number.MAX_SAFE_INTEGER){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=0,o=!1,u=0,i=0,s={request(c){if(!o){if(c<=0){e.onError(new Error(`request must be > 0, but was ${c}`));return}t=Math.min(t+c,Number.MAX_SAFE_INTEGER),r.request(c)}},unsubscribe(){o=!0,r.unsubscribe()}},l=()=>{let c=++i;this.source.subscribe({onSubscribe(b){if(c!==i){b.unsubscribe();return}r=b,t>0&&b.request(t)},onNext(b){!o&&c===i&&e.onNext(b)},onError(b){o||c!==i||(u<n?(u++,l()):e.onError(b))},onComplete(){!o&&c===i&&e.onComplete()}})};return e.onSubscribe(s),l(),s}})}scan(n){return new a({subscribe:e=>{let r,t=!1,o=this.source.subscribe({onSubscribe(u){},onNext(u){r=t?n(r,u):u,t=!0,e.onNext(r)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}scanWith(n,e){return new a({subscribe:r=>{let t=n(),o=this.source.subscribe({onSubscribe(u){},onNext(u){t=e(t,u),r.onNext(t)},onError(u){r.onError(u)},onComplete(){r.onComplete()}});return r.onSubscribe(o),o}})}zipWith(n,e){return new a({subscribe:r=>{let t=[],o=[],u=!1,i=!1,s=!1,l=!1,c={request(){},unsubscribe(){}},b={request(){},unsubscribe(){}},p=m=>{l||(l=!0,c.unsubscribe(),b.unsubscribe(),m?r.onError(m):r.onComplete())},f={request(m){if(!(s||l)){if(m<=0){p(new Error(`request must be > 0, but was ${m}`));return}c.request(m),b.request(m)}},unsubscribe(){s=!0,c.unsubscribe(),b.unsubscribe()}},S=()=>{for(;t.length>0&&o.length>0;){if(s||l)return;let m=t.shift(),d=o.shift();try{r.onNext(e(m,d))}catch(E){p(E instanceof Error?E:new Error(String(E)));return}}(u&&t.length===0||i&&o.length===0)&&p()};return this.source.subscribe({onSubscribe(m){c=m,r.onSubscribe(f)},onNext(m){!s&&!l&&(t.push(m),S())},onError(m){p(m)},onComplete(){!s&&!l&&(u=!0,S())}}),b=n.subscribe({onSubscribe(m){b=m},onNext(m){!s&&!l&&(o.push(m),S())},onError(m){p(m)},onComplete(){!s&&!l&&(i=!0,S())}}),f}})}doOnComplete(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}doOnTerminate(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n()}catch{}e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}doOnCancel(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){e.onError(o)},onComplete(){e.onComplete()}}),t={request(o){r.request(o)},unsubscribe(){try{n()}catch{}r.unsubscribe()}};return e.onSubscribe(t),t}})}doFinally(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(o){},onNext(o){e.onNext(o)},onError(o){try{n()}catch{}e.onError(o)},onComplete(){try{n()}catch{}e.onComplete()}}),t={request(o){r.request(o)},unsubscribe(){try{n()}catch{}r.unsubscribe()}};return e.onSubscribe(t),t}})}pipe(n,e,r){return new a({subscribe:t=>{n(u=>t.onNext(u),u=>t.onError(u),()=>t.onComplete());let o={request:e,unsubscribe:r};return t.onSubscribe(o),o}})}first(){return h.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(r)},onError(r){n.error(r)},onComplete(){n.complete()}});e.request(1)})}last(){return h.generate(n=>{let e,r=!1;this.source.subscribe({onSubscribe(o){},onNext(o){e=o,r=!0},onError(o){n.error(o)},onComplete(){r?n.next(e):n.complete()}}).request(Number.MAX_SAFE_INTEGER)})}count(){return h.generate(n=>{let e=0;this.source.subscribe({onSubscribe(t){},onNext(t){e++},onError(t){n.error(t)},onComplete(){n.next(e)}}).request(Number.MAX_SAFE_INTEGER)})}hasElements(){return h.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(!0)},onError(r){n.error(r)},onComplete(){n.next(!1)}});e.request(1)})}any(n){return h.generate(e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)&&(r.unsubscribe(),e.next(!0))}catch(o){e.error(o instanceof Error?o:new Error(String(o)))}},onError(t){e.error(t)},onComplete(){e.next(!1)}});r.request(Number.MAX_SAFE_INTEGER)})}all(n){return h.generate(e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)||(r.unsubscribe(),e.next(!1))}catch(o){e.error(o instanceof Error?o:new Error(String(o)))}},onError(t){e.error(t)},onComplete(){e.next(!0)}});r.request(Number.MAX_SAFE_INTEGER)})}none(n){return this.any(n).map(e=>!e)}elementAt(n,e){return h.generate(r=>{let t=0,o=this.source.subscribe({onSubscribe(u){},onNext(u){t++===n&&(o.unsubscribe(),r.next(u))},onError(u){r.error(u)},onComplete(){e!==void 0?r.next(e):r.complete()}});o.request(Number.MAX_SAFE_INTEGER)})}collect(n=!1){return h.generate(e=>{let r=[];this.source.subscribe({onSubscribe(o){},onNext(o){r.push(o)},onError(o){e.error(o)},onComplete(){e.next(r)}}).request(Number.MAX_SAFE_INTEGER)})}collectList(){return this.collect()}sort(n){return a.defer(()=>a.from(this.collect().map(e=>(e.sort(n),e)).flatMapMany(e=>a.fromIterable(e))))}buffer(n){return new a({subscribe:e=>{let r=[],t=this.source.subscribe({onSubscribe(o){},onNext(o){r.push(o),r.length>=n&&(e.onNext(r),r=[])},onError(o){e.onError(o)},onComplete(){r.length>0&&e.onNext(r),e.onComplete()}});return e.onSubscribe(t),t}})}cache(){let n=new C,e=!1;return new a({subscribe:r=>(e||(e=!0,this.source.subscribe({onSubscribe(t){t.request(Number.MAX_SAFE_INTEGER)},onNext(t){n.next(t)},onError(t){n.error(t)},onComplete(){n.complete()}})),n.subscribe(r))})}share(){let n=new Map,e=null,r=!1,t=null,o=this.source,u=()=>{r=!1,t=null,o.subscribe({onSubscribe(i){e=i,i.request(Number.MAX_SAFE_INTEGER)},onNext(i){for(let[s,l]of n)!l.cancelled&&l.demand>0&&(l.demand--,s.onNext(i))},onError(i){r=!0,t=i,e=null;for(let[s,l]of n)l.cancelled||s.onError(i);n.clear()},onComplete(){r=!0,e=null;for(let[i,s]of n)s.cancelled||i.onComplete();n.clear()}})};return new a({subscribe:i=>{if(r){let c={request(){},unsubscribe(){}};return i.onSubscribe(c),t?i.onError(t):i.onComplete(),c}let s={demand:0,cancelled:!1};n.set(i,s);let l={request(c){if(!s.cancelled){if(c<=0){s.cancelled=!0,n.delete(i),i.onError(new Error(`request must be > 0, but was ${c}`));return}s.demand=Math.min(s.demand+c,Number.MAX_SAFE_INTEGER),!e&&!r&&u()}},unsubscribe(){s.cancelled||(s.cancelled=!0,n.delete(i),n.size===0&&e&&(e.unsubscribe(),e=null))}};return i.onSubscribe(l),l}})}indexed(){return new a({subscribe:n=>{let e=0,r=this.source.subscribe({onSubscribe(t){},onNext(t){n.onNext([e++,t])},onError(t){n.onError(t)},onComplete(){n.onComplete()}});return n.onSubscribe(r),r}})}skip(n){return new a({subscribe:e=>{let r=0,t,o=this.source.subscribe({onSubscribe(u){t=u},onNext(u){r++<n?t.request(1):e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}skipWhile(n){return new a({subscribe:e=>{let r=!0,t,o=this.source.subscribe({onSubscribe(u){t=u},onNext(u){if(r&&n(u)){t.request(1);return}r=!1,e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}});return e.onSubscribe(o),o}})}skipUntil(n){return new a({subscribe:e=>{let r=!0,t,o=n.subscribe({onSubscribe(u){},onNext(u){r=!1,o.unsubscribe()},onError(u){e.onError(u)},onComplete(){}});return o.request(1),t=this.source.subscribe({onSubscribe(u){},onNext(u){r?t.request(1):e.onNext(u)},onError(u){e.onError(u)},onComplete(){e.onComplete()}}),e.onSubscribe({request(u){t.request(u)},unsubscribe(){t.unsubscribe(),o.unsubscribe()}}),{request(u){t.request(u)},unsubscribe(){t.unsubscribe(),o.unsubscribe()}}}})}distinct(){return new a({subscribe:n=>{let e=new Set,r,t=this.source.subscribe({onSubscribe(o){r=o},onNext(o){e.has(o)?r.request(1):(e.add(o),n.onNext(o))},onError(o){n.onError(o)},onComplete(){n.onComplete()}});return n.onSubscribe(t),t}})}distinctUntilChanged(n=(e,r)=>e!==r){return new a({subscribe:e=>{let r,t=!0,o,u=this.source.subscribe({onSubscribe(i){o=i},onNext(i){t||n(r,i)?(t=!1,r=i,e.onNext(i)):o.request(1)},onError(i){e.onError(i)},onComplete(){e.onComplete()}});return e.onSubscribe(u),u}})}delayElements(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i=!1,s={request(l){if(o)return;if(l<=0){e.onError(new Error(`request must be > 0, but was ${l}`));return}let c=u===0;u=Math.min(u+l,Number.MAX_SAFE_INTEGER),c&&t===null&&r.request(1)},unsubscribe(){o=!0,t?.cancel(),t=null,r.unsubscribe()}};return this.source.subscribe({onSubscribe(l){r=l,e.onSubscribe(s)},onNext(l){t=z.delay(n).schedule(()=>{t=null,!o&&(u--,e.onNext(l),!o&&(i?e.onComplete():u>0&&r.request(1)))})},onError(l){t?.cancel(),t=null,e.onError(l)},onComplete(){i=!0,t===null&&!o&&e.onComplete()}}),s}})}concatWith(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t?t.request(s):r.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){e.onNext(s)},onError(s){e.onError(s)},onComplete(){o||(t=n.subscribe({onSubscribe(s){t=s,u>0&&t.request(u)},onNext(s){e.onNext(s)},onError(s){e.onError(s)},onComplete(){e.onComplete()}}))}}),i}})}mergeWith(n){return new a({subscribe:e=>{let r=0,t=!1,o=!1,u={request(){},unsubscribe(){}},i={request(){},unsubscribe(){}},s=b=>{o||(o=!0,u.unsubscribe(),i.unsubscribe(),b?e.onError(b):e.onComplete())},l=()=>{!o&&++r===2&&s()},c={request(b){if(!(t||o)){if(b<=0){s(new Error(`request must be > 0, but was ${b}`));return}u.request(b),i.request(b)}},unsubscribe(){t=!0,u.unsubscribe(),i.unsubscribe()}};return this.source.subscribe({onSubscribe(b){u=b,e.onSubscribe(c)},onNext(b){!t&&!o&&e.onNext(b)},onError(b){s(b)},onComplete(){l()}}),i=n.subscribe({onSubscribe(b){},onNext(b){!t&&!o&&e.onNext(b)},onError(b){s(b)},onComplete(){l()}}),c}})}reduce(n){return h.generate(e=>{let r,t=!1;this.source.subscribe({onSubscribe(u){},onNext(u){r=t?n(r,u):u,t=!0},onError(u){e.error(u)},onComplete(){t?e.next(r):e.complete()}}).request(Number.MAX_SAFE_INTEGER)})}reduceWith(n,e){return h.generate(r=>{let t=n();this.source.subscribe({onSubscribe(u){},onNext(u){t=e(t,u)},onError(u){r.error(u)},onComplete(){r.next(t)}}).request(Number.MAX_SAFE_INTEGER)})}then(){return h.generate(n=>{this.source.subscribe({onSubscribe(r){},onNext(r){},onError(r){n.error(r)},onComplete(){n.next(void 0)}}).request(Number.MAX_SAFE_INTEGER)})}thenEmpty(n){return this.then().flatMap(()=>h.from({subscribe(e){let r=n.subscribe({onSubscribe(t){},onNext(t){},onError(t){e.onError(t)},onComplete(){e.onNext(void 0),e.onComplete()}});return e.onSubscribe(r),r}}))}retryWhen(n){return new a({subscribe:e=>{let r=[],t=null,o=0,u=m=>{r.push(m),i()},i=()=>{for(;o>0&&r.length>0&&t;)o--,t.onNext(r.shift())},s=new a({subscribe(m){t=m;let d={request(E){o=Math.min(o+E,Number.MAX_SAFE_INTEGER),i()},unsubscribe(){t=null}};return m.onSubscribe(d),d}}),l={request(){},unsubscribe(){}},c=0,b=!1,p=!1,f={request(m){if(!(b||p)){if(m<=0){e.onError(new Error(`request must be > 0, but was ${m}`));return}c=Math.min(c+m,Number.MAX_SAFE_INTEGER),l.request(m)}},unsubscribe(){b=!0,l.unsubscribe()}},S=()=>{this.source.subscribe({onSubscribe(m){l=m,c>0&&m.request(c)},onNext(m){!b&&!p&&e.onNext(m)},onError(m){!b&&!p&&u(m)},onComplete(){!b&&!p&&(p=!0,t?.onComplete(),e.onComplete())}})};return n(s).subscribe({onSubscribe(m){m.request(Number.MAX_SAFE_INTEGER)},onNext(m){!b&&!p&&(l.unsubscribe(),S())},onError(m){!b&&!p&&(p=!0,e.onError(m))},onComplete(){!b&&!p&&(p=!0,e.onComplete())}}),e.onSubscribe(f),S(),f}})}repeatWhen(n){return new a({subscribe:e=>{let r=[],t=null,o=0,u=!1,i=()=>{if(!u){u=!0;try{for(;!f&&!p&&o>0&&r.length>0&&t;)o--,t.onNext(r.shift())}finally{u=!1}}},s=()=>{r.push(void 0),i()},l=new a({subscribe(d){t=d;let E={request(w){o=Math.min(o+w,Number.MAX_SAFE_INTEGER),i()},unsubscribe(){t=null}};return d.onSubscribe(E),E}}),c={request(){},unsubscribe(){}},b=0,p=!1,f=!1,S={request(d){if(!(p||f)){if(d<=0){e.onError(new Error(`request must be > 0, but was ${d}`));return}b=Math.min(b+d,Number.MAX_SAFE_INTEGER),c.request(d)}},unsubscribe(){p=!0,c.unsubscribe()}},m=()=>{this.source.subscribe({onSubscribe(d){c=d,b>0&&d.request(b)},onNext(d){!p&&!f&&e.onNext(d)},onError(d){!p&&!f&&(f=!0,e.onError(d))},onComplete(){!p&&!f&&s()}})};return n(l).subscribe({onSubscribe(d){d.request(Number.MAX_SAFE_INTEGER)},onNext(d){!p&&!f&&(c.unsubscribe(),m())},onError(d){!p&&!f&&(f=!0,e.onError(d))},onComplete(){!p&&!f&&(f=!0,e.onComplete())}}),e.onSubscribe(S),m(),S}})}groupBy(n){return new a({subscribe:e=>{let r=new Map,t=!1,o={request(){},unsubscribe(){}},u={request(i){},unsubscribe(){t=!0,o.unsubscribe()}};return this.source.subscribe({onSubscribe(i){o=i,i.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(u)},onNext(i){if(t)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=r.get(s);l||(l=new C,r.set(s,l),e.onNext(Object.assign(a.from(l),{key:s}))),l.next(i)},onError(i){if(!t){for(let s of r.values())s.error(i);e.onError(i)}},onComplete(){if(!t){for(let i of r.values())i.complete();e.onComplete()}}}),u}})}bufferTimeout(n,e){return new a({subscribe:r=>{let t=[],o=null,u=!1,i=()=>{if(o!==null&&(clearTimeout(o),o=null),t.length>0&&!u){let b=t;t=[],r.onNext(b)}},s=()=>{o!==null&&clearTimeout(o),o=setTimeout(()=>{u||i()},e)},l=this.source.subscribe({onSubscribe(b){b.request(Number.MAX_SAFE_INTEGER)},onNext(b){u||(t.push(b),t.length>=n?i():s())},onError(b){u||(o!==null&&clearTimeout(o),r.onError(b))},onComplete(){u||(o!==null&&(clearTimeout(o),o=null),t.length>0&&r.onNext(t),r.onComplete())}}),c={request(b){l.request(b)},unsubscribe(){u=!0,o!==null&&clearTimeout(o),l.unsubscribe()}};return r.onSubscribe(c),c}})}sample(n){return new a({subscribe:e=>{let r,t=!1,o=!1,u={request(){},unsubscribe(){}},i={request(){},unsubscribe(){}},s={request(l){o||u.request(l)},unsubscribe(){o=!0,u.unsubscribe(),i.unsubscribe()}};return i=n.subscribe({onSubscribe(l){i=l,l.request(Number.MAX_SAFE_INTEGER)},onNext(l){if(o||!t)return;let c=r;t=!1,r=void 0,e.onNext(c)},onError(l){o||e.onError(l)},onComplete(){}}),this.source.subscribe({onSubscribe(l){u=l,e.onSubscribe(s)},onNext(l){o||(r=l,t=!0)},onError(l){o||e.onError(l)},onComplete(){o||e.onComplete()}}),s}})}delayUntil(n){return this.concatMap(e=>a.from({subscribe(r){let t=!1,o={request(){},unsubscribe(){}};return o=n(e).subscribe({onSubscribe(u){o=u,u.request(Number.MAX_SAFE_INTEGER)},onNext(u){t||(t=!0,o.unsubscribe(),r.onNext(e),r.onComplete())},onError(u){t||(t=!0,r.onError(u))},onComplete(){t||(t=!0,r.onNext(e),r.onComplete())}}),r.onSubscribe(o),o}}))}expand(n){return new a({subscribe:e=>{let r=[],t=!1,o=!1,u=!1,i=!1,s=0,l=p=>{i||(i=!0,p?e.onError(p):e.onComplete())},c=()=>{if(t||u||i)return;if(s<=0||r.length===0){o&&r.length===0&&l();return}t=!0;let p=r.shift();if(s--,e.onNext(p),u||i){t=!1;return}let f;try{f=n(p)}catch(S){t=!1,l(S instanceof Error?S:new Error(String(S)));return}f.subscribe({onSubscribe(S){S.request(Number.MAX_SAFE_INTEGER)},onNext(S){!u&&!i&&r.push(S)},onError(S){t=!1,l(S)},onComplete(){t=!1,c()}})},b={request(p){if(!(u||i)){if(p<=0){l(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){u=!0}};return this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(b)},onNext(p){!u&&!i&&(r.push(p),c())},onError(p){l(p)},onComplete(){o=!0,!t&&r.length===0&&l()}}),b}})}expandDeep(n){return new a({subscribe:e=>{let r=[],t=!1,o=!1,u=!1,i=!1,s=0,l=p=>{i||(i=!0,p?e.onError(p):e.onComplete())},c=()=>{if(t||u||i)return;if(s<=0||r.length===0){o&&r.length===0&&l();return}t=!0;let p=r.shift();if(s--,e.onNext(p),u||i){t=!1;return}let f;try{f=n(p)}catch(m){t=!1,l(m instanceof Error?m:new Error(String(m)));return}let S=[];f.subscribe({onSubscribe(m){m.request(Number.MAX_SAFE_INTEGER)},onNext(m){!u&&!i&&S.push(m)},onError(m){t=!1,l(m)},onComplete(){!u&&!i&&r.unshift(...S),t=!1,c()}})},b={request(p){if(!(u||i)){if(p<=0){l(new Error(`request must be > 0, but was ${p}`));return}s=Math.min(s+p,Number.MAX_SAFE_INTEGER),c()}},unsubscribe(){u=!0}};return this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER),e.onSubscribe(b)},onNext(p){!u&&!i&&(r.push(p),c())},onError(p){l(p)},onComplete(){o=!0,!t&&r.length===0&&l()}}),b}})}elapsed(){return new a({subscribe:n=>{let e=Date.now(),r=this.source.subscribe({onSubscribe(t){e=Date.now()},onNext(t){let o=Date.now(),u=o-e;e=o,n.onNext([u,t])},onError(t){n.onError(t)},onComplete(){n.onComplete()}});return n.onSubscribe(r),r}})}timestamp(){return this.map(n=>[Date.now(),n])}materialize(){return new a({subscribe:n=>{let e=!1,r=this.source.subscribe({onSubscribe(t){},onNext(t){e||n.onNext(N.next(t))},onError(t){e||(e=!0,n.onNext(N.error(t)),n.onComplete())},onComplete(){e||(e=!0,n.onNext(N.complete()),n.onComplete())}});return n.onSubscribe(r),r}})}dematerialize(){return new a({subscribe:n=>{let e=!1,r=this.source.subscribe({onSubscribe(t){},onNext(t){e||(t.kind==="next"?n.onNext(t.value):t.kind==="error"?(e=!0,n.onError(t.error)):(e=!0,n.onComplete()))},onError(t){e||(e=!0,n.onError(t))},onComplete(){e||(e=!0,n.onComplete())}});return n.onSubscribe(r),r}})}onBackpressureBuffer(n=Number.MAX_SAFE_INTEGER){return new a({subscribe:e=>{let r=[],t=0,o=!1,u=!1,i=null,s=!1,l=()=>{if(!(s||o)){s=!0;try{for(;t>0&&r.length>0&&!o;)t--,e.onNext(r.shift());u&&r.length===0&&!o&&(i?e.onError(i):e.onComplete())}finally{s=!1}}},c=this.source.subscribe({onSubscribe(p){p.request(Number.MAX_SAFE_INTEGER)},onNext(p){if(!o){if(r.length>=n){e.onError(new Error(`onBackpressureBuffer overflow (maxSize=${n})`));return}r.push(p),l()}},onError(p){o||(u=!0,i=p,l())},onComplete(){o||(u=!0,l())}}),b={request(p){if(!(o||u&&r.length===0)){if(p<=0){e.onError(new Error(`request must be > 0, but was ${p}`));return}t=Math.min(t+p,Number.MAX_SAFE_INTEGER),l()}},unsubscribe(){o=!0,r.length=0,c.unsubscribe()}};return e.onSubscribe(b),b}})}onBackpressureDrop(n){return new a({subscribe:e=>{let r=0,t=!1,o=this.source.subscribe({onSubscribe(i){i.request(Number.MAX_SAFE_INTEGER)},onNext(i){if(!t)if(r>0)r--,e.onNext(i);else try{n?.(i)}catch{}},onError(i){t||e.onError(i)},onComplete(){t||e.onComplete()}}),u={request(i){if(!t){if(i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}r=Math.min(r+i,Number.MAX_SAFE_INTEGER)}},unsubscribe(){t=!0,o.unsubscribe()}};return e.onSubscribe(u),u}})}onBackpressureLatest(){return new a({subscribe:n=>{let e,r=!1,t=0,o=!1,u=!1,i=null,s=()=>{if(!o){if(t>0&&r){t--;let b=e;r=!1,e=void 0,n.onNext(b)}u&&!r&&!o&&(i?n.onError(i):n.onComplete())}},l=this.source.subscribe({onSubscribe(b){b.request(Number.MAX_SAFE_INTEGER)},onNext(b){o||(e=b,r=!0,s())},onError(b){o||(u=!0,i=b,s())},onComplete(){o||(u=!0,s())}}),c={request(b){if(!(o||u&&!r)){if(b<=0){n.onError(new Error(`request must be > 0, but was ${b}`));return}t=Math.min(t+b,Number.MAX_SAFE_INTEGER),s()}},unsubscribe(){o=!0,l.unsubscribe()}};return n.onSubscribe(c),c}})}limitRate(n){return new a({subscribe:e=>{let r=Math.max(1,n),t=Math.max(1,Math.floor(r*.75)),o,u=0,i=0,s=!1,l=()=>{let b=r-u;b>0&&(u+=b,o.request(b))},c={request(b){if(!s){if(b<=0){e.onError(new Error(`request must be > 0, but was ${b}`));return}l()}},unsubscribe(){s=!0,o?.unsubscribe()}};return this.source.subscribe({onSubscribe(b){o=b,e.onSubscribe(c)},onNext(b){s||(u=Math.max(0,u-1),i++,e.onNext(b),i>=t&&(i=0,l()))},onError(b){s||e.onError(b)},onComplete(){s||e.onComplete()}}),c}})}ofType(n){return this.filter(e=>e instanceof n).cast()}transformDeferred(n){return a.defer(()=>a.from(n(this)))}};var h=class a extends R{constructor(n){super(n)}defaultDemand(){return 1}wrapSource(n){return new a(n)}static generate(n){return new a({subscribe(e){let r=!1,t=!1,o=!1,u=null,i=null,s=()=>{if(!(r||!t))if(u!==null){let b=u.value;u=null,e.onNext(b),r||e.onComplete()}else if(i!==null){let b=i;i=null,e.onError(b)}else o&&e.onComplete()},l={next(b){o||r||(o=!0,t?(e.onNext(b),r||e.onComplete()):u={value:b})},error(b){o||r||(o=!0,t?e.onError(b):i=b)},complete(){o||r||(o=!0,t&&e.onComplete())}};try{n(l)}catch(b){o||(o=!0,i=b instanceof Error?b:new Error(String(b)))}let c={request(b){if(!(r||t)){if(b<=0){e.onError(new Error(`request must be > 0, but was ${b}`));return}t=!0,s()}},unsubscribe(){r=!0}};return e.onSubscribe(c),c}})}static from(n){return new a(n)}static just(n){return a.generate(e=>e.next(n))}static justOrEmpty(n){return n!=null?a.just(n):a.empty()}static empty(){return new a({subscribe(n){let e={request(){},unsubscribe(){}};return n.onSubscribe(e),n.onComplete(),e}})}static error(n){let e=n instanceof Error?n:new Error(String(n));return new a({subscribe(r){let t={request(){},unsubscribe(){}};return r.onSubscribe(t),r.onError(e),t}})}static fromPromise(n){return a.generate(e=>n.then(r=>e.next(r)).catch(r=>e.error(r instanceof Error?r:new Error(String(r)))))}static defer(n){return new a({subscribe(e){return n().subscribe(e)}})}static create(n){return a.generate(n)}static delay(n){return a.generate(e=>{let r=setTimeout(()=>e.next(0),n)})}static fromCallable(n){return a.generate(e=>{try{e.next(n())}catch(r){e.error(r instanceof Error?r:new Error(String(r)))}})}static firstWithValue(...n){return n.length===0?a.empty():a.generate(e=>{let r=!1,t=0,o=[];for(let u of n){let i=u.subscribe({onSubscribe(s){},onNext(s){if(!r){r=!0;for(let l of o)l.unsubscribe();e.next(s)}},onError(s){if(!r){r=!0;for(let l of o)l.unsubscribe();e.error(s)}},onComplete(){r||(t++,t===n.length&&(r=!0,e.complete()))}});o.push(i)}for(let u of o)u.request(1)})}static when(...n){return n.length===0?a.empty():a.generate(e=>{let r=!1,t=0,o=[];for(let u of n){let i=u.subscribe({onSubscribe(s){},onNext(s){},onError(s){if(!r){r=!0;for(let l of o)l.unsubscribe();e.error(s)}},onComplete(){r||(t++,t===n.length&&(r=!0,e.complete()))}});o.push(i)}for(let u of o)u.request(Number.MAX_SAFE_INTEGER)})}map(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{e.onNext(n(t))}catch(o){e.onError(o instanceof Error?o:new Error(String(o)))}},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}mapNotNull(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(!r)try{let u=n(o);u!=null?e.onNext(u):(r=!0,e.onComplete())}catch(u){r=!0,e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onComplete())}});return e.onSubscribe(t),t}})}flatMap(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t&&t.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}}),u>0&&t.request(u)},onError(s){e.onError(s)},onComplete(){t||e.onComplete()}}),r.request(1),i}})}filter(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){if(!r)try{n(o)?e.onNext(o):(r=!0,e.onComplete())}catch(u){r=!0,e.onError(u instanceof Error?u:new Error(String(u)))}},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onComplete())}});return e.onSubscribe(t),t}})}filterWhen(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u={request(i){if(!o&&i<=0){e.onError(new Error(`request must be > 0, but was ${i}`));return}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){if(o)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=!1;t=s.subscribe({onSubscribe(c){},onNext(c){l||(l=!0,c?e.onNext(i):e.onComplete())},onError(c){l||(l=!0,e.onError(c))},onComplete(){l||(l=!0,e.onComplete())}}),t.request(1)},onError(i){e.onError(i)},onComplete(){t||e.onComplete()}}),r.request(1),u}})}cast(){return new a(this.source)}doFinally(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){try{n()}catch{}e.onError(t)},onComplete(){try{n()}catch{}e.onComplete()}});return e.onSubscribe(r),r}})}pipe(n,e,r){return new a({subscribe:t=>{n(u=>t.onNext(u),u=>t.onError(u),()=>t.onComplete());let o={request:e,unsubscribe:r};return t.onSubscribe(o),o}})}flatMapMany(n){return T.from({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t&&t.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){if(o)return;let l;try{l=n(s)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}t=l.subscribe({onSubscribe(c){},onNext(c){e.onNext(c)},onError(c){e.onError(c)},onComplete(){e.onComplete()}}),u>0&&t.request(u)},onError(s){e.onError(s)},onComplete(){t||e.onComplete()}}),r.request(1),i}})}zipWith(n){return a.generate(e=>{let r,t,o=!1,u=!1,i=!1,s=p=>{i||(i=!0,c?.unsubscribe(),b?.unsubscribe(),e.error(p))},l=()=>{o&&u&&e.next([r,t])},c,b;c=this.source.subscribe({onSubscribe(p){},onNext(p){r=p,o=!0,l()},onError(p){s(p)},onComplete(){o||(b?.unsubscribe(),e.complete())}}),b=n.subscribe({onSubscribe(p){},onNext(p){t=p,u=!0,l()},onError(p){s(p)},onComplete(){u||(c?.unsubscribe(),e.complete())}}),c.request(1),b.request(1)})}zipWhen(n){return a.generate(e=>{this.source.subscribe({onSubscribe(t){},onNext(t){let o;try{o=n(t)}catch(i){e.error(i instanceof Error?i:new Error(String(i)));return}o.subscribe({onSubscribe(i){},onNext(i){e.next([t,i])},onError(i){e.error(i)},onComplete(){e.complete()}}).request(1)},onError(t){e.error(t)},onComplete(){e.complete()}}).request(1)})}hasElement(){return a.generate(n=>{let e=this.source.subscribe({onSubscribe(r){},onNext(r){e.unsubscribe(),n.next(!0)},onError(r){n.error(r)},onComplete(){n.next(!1)}});e.request(1)})}doOnSuccess(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){try{n(t)}catch(o){e.onError(o instanceof Error?o:new Error(String(o)));return}e.onNext(t)},onError(t){e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}onErrorComplete(n){return new a({subscribe:e=>{let r=this.source.subscribe({onSubscribe(t){},onNext(t){e.onNext(t)},onError(t){!n||n(t)?e.onComplete():e.onError(t)},onComplete(){e.onComplete()}});return e.onSubscribe(r),r}})}thenReturn(n){return new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onNext(n),e.onComplete())}});return e.onSubscribe(t),t}})}then(n){return n?new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=0,i={request(s){if(!o){if(s<=0){e.onError(new Error(`request must be > 0, but was ${s}`));return}u=Math.min(u+s,Number.MAX_SAFE_INTEGER),t&&t.request(s)}},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){},onError(s){o||e.onError(s)},onComplete(){o||(t=n.subscribe({onSubscribe(s){},onNext(s){e.onNext(s)},onError(s){e.onError(s)},onComplete(){e.onComplete()}}),u>0&&t.request(u))}}),r.request(1),i}}):new a({subscribe:e=>{let r=!1,t=this.source.subscribe({onSubscribe(o){},onNext(o){},onError(o){r||(r=!0,e.onError(o))},onComplete(){r||(r=!0,e.onComplete())}});return e.onSubscribe(t),t}})}delayElement(n){return new a({subscribe:e=>{let r=null,t=!1,o=this.source.subscribe({onSubscribe(i){},onNext(i){t||(r=setTimeout(()=>{t||(e.onNext(i),e.onComplete())},n))},onError(i){e.onError(i)},onComplete(){}}),u={request(i){o.request(i)},unsubscribe(){t=!0,r!==null&&clearTimeout(r),o.unsubscribe()}};return e.onSubscribe(u),u}})}delayUntil(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u={request(i){o||r.request(i)},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(i){r=i,e.onSubscribe(u)},onNext(i){if(o)return;let s;try{s=n(i)}catch(c){e.onError(c instanceof Error?c:new Error(String(c)));return}let l=!1;t=s.subscribe({onSubscribe(c){},onNext(c){l||o||(l=!0,t?.unsubscribe(),e.onNext(i),e.onComplete())},onError(c){o||e.onError(c)},onComplete(){!l&&!o&&(l=!0,e.onNext(i),e.onComplete())}}),t.request(Number.MAX_SAFE_INTEGER)},onError(i){o||e.onError(i)},onComplete(){!o&&!t&&e.onComplete()}}),u}})}or(n){return new a({subscribe:e=>{let r={request(){},unsubscribe(){}},t=null,o=!1,u=!1,i={request(s){o||(t?t.request(s):r.request(s))},unsubscribe(){o=!0,r.unsubscribe(),t?.unsubscribe()}};return this.source.subscribe({onSubscribe(s){r=s,e.onSubscribe(i)},onNext(s){o||(u=!0,e.onNext(s))},onError(s){o||e.onError(s)},onComplete(){o||u||(t=n.subscribe({onSubscribe(s){},onNext(s){o||e.onNext(s)},onError(s){o||e.onError(s)},onComplete(){o||e.onComplete()}}),t.request(1))}}),i}})}retryWhen(n){return new a({subscribe:e=>{let r=!1,t=null,o=!1,u=null,i=T.from({subscribe(f){u={onNext:m=>f.onNext(m)};let S={request(m){},unsubscribe(){r=!0}};return f.onSubscribe(S),S}}),s=n(i),l,c=()=>{r||o||(t=this.source.subscribe({onSubscribe(f){},onNext(f){r||o||(o=!0,e.onNext(f),e.onComplete())},onError(f){r||u?.onNext(f)},onComplete(){!r&&!o&&e.onComplete()}}),t.request(1))},b=s.subscribe({onSubscribe(f){},onNext(f){!r&&!o&&c()},onError(f){r||e.onError(f)},onComplete(){!r&&!o&&e.onComplete()}});b.request(Number.MAX_SAFE_INTEGER),l={onNext:f=>{!r&&!o&&c()},onError:f=>{r||e.onError(f)},onComplete:()=>{!r&&!o&&e.onComplete()}},c();let p={request(f){},unsubscribe(){r=!0,t?.unsubscribe(),b.unsubscribe()}};return e.onSubscribe(p),p}})}toFuture(){return this.toPromise()}toPromise(){return new Promise((n,e)=>{let r=null;this.subscribe({onSubscribe(o){},onNext(o){r=o},onError(o){e(o)},onComplete(){n(r)}}).request(Number.MAX_SAFE_INTEGER)})}};var v=class{constructor(){this.pendingValue=null;this.completed=!1;this.terminalError=null;this.entries=new Map}get terminated(){return this.completed||this.terminalError!==null}next(n){this.terminated||this.pendingValue!==null||(this.pendingValue={value:n})}error(n){if(!this.terminated){this.terminalError=n;for(let[e,r]of this.entries)r.cancelled||e.onError(n);this.entries.clear()}}complete(){if(!this.terminated){this.completed=!0;for(let[n,e]of this.entries)e.cancelled||(this.pendingValue===null?(n.onComplete(),this.entries.delete(n)):e.demand>=1?(e.demand--,n.onNext(this.pendingValue.value),e.cancelled||n.onComplete(),this.entries.delete(n)):e.completionQueued=!0)}}asFlux(){return T.from(this)}subscribe(n){if(this.terminalError){let t={request(){},unsubscribe(){}};return n.onSubscribe(t),n.onError(this.terminalError),t}let e={demand:0,cancelled:!1,completionQueued:this.completed};if(this.entries.set(n,e),this.completed&&this.pendingValue===null){this.entries.delete(n);let t={request(){},unsubscribe(){}};return n.onSubscribe(t),n.onComplete(),t}let r={request:t=>{if(!e.cancelled){if(t<=0){e.cancelled=!0,this.entries.delete(n),n.onError(new Error(`request must be > 0, but was ${t}`));return}e.demand=Math.min(e.demand+t,Number.MAX_SAFE_INTEGER),e.completionQueued&&this.pendingValue!==null&&e.demand>=1&&(e.demand--,e.cancelled=!0,this.entries.delete(n),n.onNext(this.pendingValue.value),n.onComplete())}},unsubscribe:()=>{e.cancelled=!0,this.entries.delete(n)}};return n.onSubscribe(r),r}};var g=class{constructor(){this.terminal=null;this.subscribers=new Set}next(n){}error(n){if(!this.terminal){this.terminal={kind:"error",error:n};for(let e of this.subscribers)e.onError(n);this.subscribers.clear()}}complete(){if(!this.terminal){this.terminal={kind:"completed"};for(let n of this.subscribers)n.onComplete();this.subscribers.clear()}}asFlux(){return T.from(this)}subscribe(n){if(this.terminal){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),this.terminal.kind==="completed"?n.onComplete():n.onError(this.terminal.error),r}this.subscribers.add(n);let e={request:r=>{this.subscribers.has(n)&&r<=0&&(this.subscribers.delete(n),n.onError(new Error(`request must be > 0, but was ${r}`)))},unsubscribe:()=>{this.subscribers.delete(n)}};return n.onSubscribe(e),e}};var q=class{constructor(){this.subscriber=null;this.demand=0;this.cancelled=!1;this.terminated=!1;this.terminalError=null}asFlux(){return T.from(this)}shouldReplayTerminalOnSubscribe(){return this.terminated}onDemandGranted(){}onUnsubscribed(){}afterSubscribed(){}onTerminal(){this.subscriber&&!this.cancelled&&(this.terminalError?this.subscriber.onError(this.terminalError):this.subscriber.onComplete())}error(n){this.terminated||(this.terminated=!0,this.terminalError=n,this.onTerminal())}complete(){this.terminated||(this.terminated=!0,this.onTerminal())}subscribe(n){if(this.subscriber!==null){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),n.onError(new Error(`${this.constructor.name} allows only one subscriber`)),r}if(this.shouldReplayTerminalOnSubscribe()){let r={request(){},unsubscribe(){}};return n.onSubscribe(r),this.terminalError?n.onError(this.terminalError):n.onComplete(),r}this.subscriber=n;let e={request:r=>{if(!this.cancelled){if(r<=0){this.cancelled=!0;let t=this.subscriber;this.subscriber=null,t?.onError(new Error(`request must be > 0, but was ${r}`));return}this.demand=Math.min(this.demand+r,Number.MAX_SAFE_INTEGER),this.onDemandGranted()}},unsubscribe:()=>{this.cancelled=!0,this.subscriber=null,this.onUnsubscribed()}};return n.onSubscribe(e),this.afterSubscribed(),e}};var M=class extends q{constructor(){super(...arguments);this.buffer=[];this.draining=!1}shouldReplayTerminalOnSubscribe(){return!1}onTerminal(){this.drain()}onDemandGranted(){this.drain()}onUnsubscribed(){this.buffer.length=0}afterSubscribed(){this.drain()}next(e){this.terminated||this.cancelled||(this.buffer.push(e),this.drain())}drain(){if(!(!this.subscriber||this.cancelled||this.draining)){this.draining=!0;try{for(;this.demand>0&&this.buffer.length>0;)if(this.demand--,this.subscriber.onNext(this.buffer.shift()),this.cancelled)return;if(this.buffer.length===0&&this.terminated){let e=this.subscriber;this.subscriber=null,this.terminalError?e.onError(this.terminalError):e.onComplete()}}finally{this.draining=!1}}}};var F=class extends q{next(n){if(!(this.terminated||this.cancelled||!this.subscriber)){if(this.demand<=0){this.error(new Error("UnicastOnBackpressureErrorSink: subscriber cannot keep up with demand"));return}this.demand--,this.subscriber.onNext(n)}}};var A=class extends x{createEntry(){return{demand:0,cancelled:!1}}next(n){if(this.terminated)return;let e=[...this.entries.values()].filter(r=>!r.cancelled);if(!(e.length===0||!e.every(r=>r.demand>0)))for(let[r,t]of this.entries)t.cancelled||(t.demand--,r.onNext(n))}};var _=class extends x{createEntry(){return{demand:0,cancelled:!1}}next(n){if(!this.terminated)for(let[e,r]of this.entries)!r.cancelled&&r.demand>0&&(r.demand--,e.onNext(n))}};var P=class extends x{constructor(n=256,e=!0){super(),this.bufferSize=n,this.autoCancel=e}createEntry(){return{buffer:[],demand:0,cancelled:!1,draining:!1}}deliverComplete(n,e){this.drainEntry(n,e)}clearEntriesAfterComplete(){return!1}onDemandGranted(n,e){this.drainEntry(n,e)}onUnsubscribed(n,e){this.autoCancel&&this.entries.size===0&&(this.terminated=!0)}next(n){if(!this.terminated)for(let[e,r]of this.entries)r.cancelled||(r.demand>0?(r.demand--,e.onNext(n)):r.buffer.length<this.bufferSize?r.buffer.push(n):(r.cancelled=!0,this.entries.delete(e),e.onError(new Error("MulticastOnBackpressureBufferSink: buffer overflow")),this.autoCancel&&this.entries.size===0&&(this.terminated=!0)))}drainEntry(n,e){if(!(e.cancelled||e.draining)){e.draining=!0;try{for(;e.demand>0&&e.buffer.length>0;)if(e.demand--,n.onNext(e.buffer.shift()),e.cancelled)return;e.buffer.length===0&&this.terminated&&(this.entries.delete(n),this.terminalError?n.onError(this.terminalError):n.onComplete())}finally{e.draining=!1}}}};var y=class extends x{constructor(e){super();this.history=[];this.limit=e}createEntry(){return{replay:[...this.history],demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.history.length===0}deliverError(e,r){this.drainEntry(e,r),r.cancelled||e.onError(this.terminalError)}deliverComplete(e,r){r.cancelled||this.drainEntry(e,r)}clearEntriesAfterComplete(){return!1}onDemandGranted(e,r){this.drainEntry(e,r)}next(e){if(!this.terminated){this.history.push(e),this.history.length>this.limit&&this.history.shift();for(let[r,t]of this.entries)t.cancelled||(t.replay.push(e),this.drainEntry(r,t))}}drainEntry(e,r){if(!(r.cancelled||r.draining)){r.draining=!0;try{for(;r.demand>0&&r.replay.length>0;)if(r.demand--,e.onNext(r.replay.shift()),r.cancelled)return;r.replay.length===0&&this.terminated&&(this.entries.delete(e),this.terminalError?e.onError(this.terminalError):e.onComplete())}finally{r.draining=!1}}}};var k=class extends x{constructor(n){super(),this.latestValue=n}createEntry(){return{pending:this.latestValue,hasPending:!0,demand:0,cancelled:!1,draining:!1}}shouldReplayTerminalOnSubscribe(){return this.terminated&&this.terminalError!==null}deliverError(n,e){this.drainEntry(n,e),e.cancelled||n.onError(this.terminalError)}deliverComplete(n,e){e.cancelled||this.drainEntry(n,e)}clearEntriesAfterComplete(){return!1}onDemandGranted(n,e){this.drainEntry(n,e)}next(n){if(!this.terminated){this.latestValue=n;for(let[e,r]of this.entries)r.cancelled||(r.pending=n,r.hasPending=!0,this.drainEntry(e,r))}}drainEntry(n,e){if(!(e.cancelled||e.draining)){e.draining=!0;try{if(e.hasPending&&e.demand>0&&(e.demand--,e.hasPending=!1,n.onNext(e.pending),e.cancelled))return;!e.hasPending&&this.terminated&&(this.entries.delete(n),this.terminalError?n.onError(this.terminalError):n.onComplete())}finally{e.draining=!1}}}};var Z={empty:()=>new g,one:()=>new v,many:()=>({multicast:()=>({directAllOrNothing:()=>new A,directBestEffort:()=>new _,onBackpressureBuffer:(a=256,n=!0)=>new P(a,n)}),unicast:()=>({onBackpressureBuffer:()=>new M,onBackpressureError:()=>new F}),replay:()=>({all:()=>new C,latest:a=>new y(a),latestOrDefault:a=>new k(a),limit:a=>new y(a)})})};0&&(module.exports={Flux,Mono,Schedulers,Signal,Sinks});
|
|
2
2
|
//# sourceMappingURL=index.js.map
|