reactor-core-ts 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +118 -10
- package/dist/index.d.mts +808 -6
- package/dist/index.d.ts +808 -6
- 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/dist/index.d.mts
CHANGED
|
@@ -227,6 +227,45 @@ interface PipePublisher<T> extends Publisher<T> {
|
|
|
227
227
|
subscribeOn(scheduler: Scheduler): PipePublisher<T>;
|
|
228
228
|
}
|
|
229
229
|
|
|
230
|
+
/**
|
|
231
|
+
* Represents a reactive signal — one of the three events that can be emitted
|
|
232
|
+
* by a {@link Publisher}: a value (`next`), a terminal error (`error`), or
|
|
233
|
+
* a normal completion (`complete`).
|
|
234
|
+
*
|
|
235
|
+
* `Signal` is the type used by {@link Flux#materialize} /
|
|
236
|
+
* {@link Flux#dematerialize} to pass reactive events as plain data values.
|
|
237
|
+
*
|
|
238
|
+
* @typeParam T - The type of the value carried by a `next` signal.
|
|
239
|
+
*/
|
|
240
|
+
type Signal<T> = {
|
|
241
|
+
readonly kind: 'next';
|
|
242
|
+
readonly value: T;
|
|
243
|
+
} | {
|
|
244
|
+
readonly kind: 'error';
|
|
245
|
+
readonly error: Error;
|
|
246
|
+
} | {
|
|
247
|
+
readonly kind: 'complete';
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* Namespace of factory helpers for creating {@link Signal} instances.
|
|
251
|
+
*/
|
|
252
|
+
declare const Signal: {
|
|
253
|
+
/**
|
|
254
|
+
* Creates a `next` signal carrying `value`.
|
|
255
|
+
* @param value - The item to wrap.
|
|
256
|
+
*/
|
|
257
|
+
next<T>(value: T): Signal<T>;
|
|
258
|
+
/**
|
|
259
|
+
* Creates an `error` signal carrying `error`.
|
|
260
|
+
* @param error - The error to wrap.
|
|
261
|
+
*/
|
|
262
|
+
error<T>(error: Error): Signal<T>;
|
|
263
|
+
/**
|
|
264
|
+
* Creates a `complete` signal.
|
|
265
|
+
*/
|
|
266
|
+
complete<T>(): Signal<T>;
|
|
267
|
+
};
|
|
268
|
+
|
|
230
269
|
/**
|
|
231
270
|
* Base class for Flux and Mono providing the common operator implementations
|
|
232
271
|
* that are identical across both types. Operators that preserve T use the
|
|
@@ -352,6 +391,114 @@ declare abstract class AbstractPipePublisher<T, Self> implements Publisher<T> {
|
|
|
352
391
|
* @returns A publisher that delivers signals on the given scheduler.
|
|
353
392
|
*/
|
|
354
393
|
publishOn(scheduler: Scheduler): Self;
|
|
394
|
+
/**
|
|
395
|
+
* Falls back to a publisher produced by `fn` when the source signals an error.
|
|
396
|
+
*
|
|
397
|
+
* Unlike {@link onErrorReturn} (which takes a static replacement), this operator
|
|
398
|
+
* calls `fn` with the actual error, allowing dynamic recovery based on the error type.
|
|
399
|
+
*
|
|
400
|
+
* @param fn - Called with the error; returns the replacement publisher.
|
|
401
|
+
* @returns A publisher that recovers from errors dynamically.
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* Flux.error(new Error('not found'))
|
|
406
|
+
* .onErrorResume(e => e.message === 'not found' ? Flux.just('default') : Flux.error(e))
|
|
407
|
+
* .subscribe(v => console.log(v)); // 'default'
|
|
408
|
+
* ```
|
|
409
|
+
*/
|
|
410
|
+
onErrorResume(fn: (error: Error) => Publisher<T>): Self;
|
|
411
|
+
/**
|
|
412
|
+
* Transforms the error signal using `fn` before forwarding it downstream.
|
|
413
|
+
*
|
|
414
|
+
* Useful for converting low-level errors into domain-specific error types.
|
|
415
|
+
*
|
|
416
|
+
* @param fn - Receives the original error and returns a replacement error.
|
|
417
|
+
* @returns A publisher that transforms errors before propagating them.
|
|
418
|
+
*
|
|
419
|
+
* @example
|
|
420
|
+
* ```typescript
|
|
421
|
+
* Flux.error(new Error('HTTP 404'))
|
|
422
|
+
* .onErrorMap(e => new Error(`NotFound: ${e.message}`))
|
|
423
|
+
* .subscribe(null, e => console.error(e.message)); // NotFound: HTTP 404
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
onErrorMap(fn: (error: Error) => Error): Self;
|
|
427
|
+
/**
|
|
428
|
+
* Emits a `TimeoutError` (or switches to `fallback`) if no item is received
|
|
429
|
+
* within `ms` milliseconds of the previous item (or of subscription).
|
|
430
|
+
*
|
|
431
|
+
* The timer resets on each received item, so it measures **inter-item** idle time.
|
|
432
|
+
*
|
|
433
|
+
* @param ms - Timeout duration in milliseconds.
|
|
434
|
+
* @param fallback - Optional publisher to switch to on timeout instead of erroring.
|
|
435
|
+
* @returns A publisher that errors or falls back when no item arrives in time.
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```typescript
|
|
439
|
+
* Flux.never<number>()
|
|
440
|
+
* .timeout(100)
|
|
441
|
+
* .subscribe(null, e => console.error(e.message)); // TimeoutError after 100ms
|
|
442
|
+
* ```
|
|
443
|
+
*/
|
|
444
|
+
timeout(ms: number, fallback?: Publisher<T>): Self;
|
|
445
|
+
/**
|
|
446
|
+
* Delays the subscription to the upstream source by `ms` milliseconds.
|
|
447
|
+
*
|
|
448
|
+
* `onSubscribe` is delivered immediately with a proxy `Subscription`.
|
|
449
|
+
* Any `request(n)` calls before the delay elapses are accumulated and
|
|
450
|
+
* forwarded once the actual subscription starts.
|
|
451
|
+
*
|
|
452
|
+
* @param ms - Delay in milliseconds before subscribing to the source.
|
|
453
|
+
* @returns A publisher whose upstream subscription is deferred.
|
|
454
|
+
*/
|
|
455
|
+
delaySubscription(ms: number): Self;
|
|
456
|
+
/**
|
|
457
|
+
* Logs each reactive signal to the console for debugging.
|
|
458
|
+
*
|
|
459
|
+
* Prints `onSubscribe`, `request(n)`, `onNext(value)`, `onError`, `onComplete`,
|
|
460
|
+
* and `cancel` with an optional label prefix.
|
|
461
|
+
*
|
|
462
|
+
* @param label - Optional label prepended to each log line (default: `'reactor'`).
|
|
463
|
+
* @returns A publisher with logging side effects attached.
|
|
464
|
+
*
|
|
465
|
+
* @example
|
|
466
|
+
* ```typescript
|
|
467
|
+
* Flux.just(1, 2).log('source').subscribe(v => console.log(v));
|
|
468
|
+
* // [source] onSubscribe
|
|
469
|
+
* // [source] request(9007199254740991)
|
|
470
|
+
* // [source] onNext(1)
|
|
471
|
+
* // ...
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
log(label?: string): Self;
|
|
475
|
+
/**
|
|
476
|
+
* Executes a side-effect `fn` whenever the downstream subscriber issues a `request(n)`.
|
|
477
|
+
*
|
|
478
|
+
* Useful for debugging backpressure — see exactly how much demand is flowing upstream.
|
|
479
|
+
* Any exception thrown by `fn` is silently swallowed.
|
|
480
|
+
*
|
|
481
|
+
* @param fn - Called with the requested count `n`.
|
|
482
|
+
* @returns A publisher with the side effect attached to the request signal.
|
|
483
|
+
*/
|
|
484
|
+
doOnRequest(fn: (n: number) => void): Self;
|
|
485
|
+
/**
|
|
486
|
+
* Executes a side-effect `fn` for every reactive signal (next, error, complete).
|
|
487
|
+
*
|
|
488
|
+
* The {@link Signal} discriminated union lets you inspect the kind and payload
|
|
489
|
+
* of each event in a single callback.
|
|
490
|
+
*
|
|
491
|
+
* @param fn - Called for every signal with a {@link Signal} wrapper.
|
|
492
|
+
* @returns A publisher with the side effect attached to all signals.
|
|
493
|
+
*
|
|
494
|
+
* @example
|
|
495
|
+
* ```typescript
|
|
496
|
+
* Flux.just(1, 2)
|
|
497
|
+
* .doOnEach(s => { if (s.kind === 'next') console.log('item:', s.value); })
|
|
498
|
+
* .subscribe();
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
doOnEach(fn: (signal: Signal<T>) => void): Self;
|
|
355
502
|
/**
|
|
356
503
|
* Shifts the *subscription* (and source execution) to the given `scheduler`.
|
|
357
504
|
*
|
|
@@ -368,6 +515,60 @@ declare abstract class AbstractPipePublisher<T, Self> implements Publisher<T> {
|
|
|
368
515
|
subscribeOn(scheduler: Scheduler): Self;
|
|
369
516
|
}
|
|
370
517
|
|
|
518
|
+
/**
|
|
519
|
+
* Backpressure-aware push interface handed to the generator function of {@link Flux.create}.
|
|
520
|
+
*
|
|
521
|
+
* Extends {@link Sink} with demand tracking and lifecycle hooks so the producer
|
|
522
|
+
* can react to downstream request signals and cancellation. The generator may call
|
|
523
|
+
* `next`, `error`, and `complete` freely from any context (event listener, timer,
|
|
524
|
+
* callback). Items pushed when downstream demand is zero are buffered and delivered
|
|
525
|
+
* as soon as demand becomes available.
|
|
526
|
+
*
|
|
527
|
+
* @typeParam T - The type of items to push.
|
|
528
|
+
*/
|
|
529
|
+
interface FluxSink<T> extends Sink<T> {
|
|
530
|
+
/**
|
|
531
|
+
* Push the next value. Buffered if downstream has no outstanding demand.
|
|
532
|
+
* No-op after `complete()` or `error()` have been called.
|
|
533
|
+
*/
|
|
534
|
+
next(value: T): void;
|
|
535
|
+
/**
|
|
536
|
+
* Terminate the stream with an error.
|
|
537
|
+
* No-op if the sink has already terminated.
|
|
538
|
+
*/
|
|
539
|
+
error(error: Error): void;
|
|
540
|
+
/**
|
|
541
|
+
* Complete the stream normally.
|
|
542
|
+
* No-op if the sink has already terminated.
|
|
543
|
+
*/
|
|
544
|
+
complete(): void;
|
|
545
|
+
/**
|
|
546
|
+
* The current downstream demand (number of items the subscriber has requested
|
|
547
|
+
* but not yet received). Useful for push-pull hybrid sources.
|
|
548
|
+
*/
|
|
549
|
+
readonly requested: number;
|
|
550
|
+
/**
|
|
551
|
+
* Register a callback that is called each time downstream requests more items.
|
|
552
|
+
* Multiple callbacks may be registered; they are all called in registration order.
|
|
553
|
+
* @param fn - Called with the additional demand count.
|
|
554
|
+
* @returns `this` for chaining.
|
|
555
|
+
*/
|
|
556
|
+
onRequest(fn: (n: number) => void): FluxSink<T>;
|
|
557
|
+
/**
|
|
558
|
+
* Register a callback that is called when downstream cancels (unsubscribes).
|
|
559
|
+
* @param fn - Cancellation handler.
|
|
560
|
+
* @returns `this` for chaining.
|
|
561
|
+
*/
|
|
562
|
+
onCancel(fn: () => void): FluxSink<T>;
|
|
563
|
+
/**
|
|
564
|
+
* Register a callback that is called when the sink is disposed —
|
|
565
|
+
* either by cancellation or terminal signal.
|
|
566
|
+
* @param fn - Disposal handler.
|
|
567
|
+
* @returns `this` for chaining.
|
|
568
|
+
*/
|
|
569
|
+
onDispose(fn: () => void): FluxSink<T>;
|
|
570
|
+
}
|
|
571
|
+
|
|
371
572
|
/**
|
|
372
573
|
* A cold publisher of 0 to N items with full backpressure support.
|
|
373
574
|
*
|
|
@@ -494,6 +695,158 @@ declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipeP
|
|
|
494
695
|
* @returns A `Flux<T>` that stays subscribed forever.
|
|
495
696
|
*/
|
|
496
697
|
static never<T = never>(): Flux<T>;
|
|
698
|
+
/**
|
|
699
|
+
* Creates a `Flux` from a generator function that **pushes** values imperatively
|
|
700
|
+
* via a {@link FluxSink}.
|
|
701
|
+
*
|
|
702
|
+
* Unlike {@link Flux.generate} (which is request-pull), `create` is designed for
|
|
703
|
+
* **push-based** sources (EventEmitter, WebSocket, DOM events, Node.js streams).
|
|
704
|
+
* Items pushed when downstream demand is zero are **buffered** and delivered as demand
|
|
705
|
+
* becomes available.
|
|
706
|
+
*
|
|
707
|
+
* Register `onRequest`, `onCancel`, and `onDispose` callbacks on the sink to respond
|
|
708
|
+
* to downstream lifecycle events.
|
|
709
|
+
*
|
|
710
|
+
* @param emitter - Called once per subscription; receives a `FluxSink<T>` for pushing values.
|
|
711
|
+
* @returns A cold `Flux<T>`.
|
|
712
|
+
*
|
|
713
|
+
* @example
|
|
714
|
+
* ```typescript
|
|
715
|
+
* const emitter = new EventEmitter();
|
|
716
|
+
* const flux = Flux.create<string>(sink => {
|
|
717
|
+
* emitter.on('data', v => sink.next(v));
|
|
718
|
+
* emitter.on('end', () => sink.complete());
|
|
719
|
+
* sink.onCancel(() => emitter.removeAllListeners());
|
|
720
|
+
* });
|
|
721
|
+
* ```
|
|
722
|
+
*/
|
|
723
|
+
static create<T>(emitter: (sink: FluxSink<T>) => void): Flux<T>;
|
|
724
|
+
/**
|
|
725
|
+
* Creates a `Flux` that acquires a resource, uses it to build a source publisher,
|
|
726
|
+
* and guarantees the resource is cleaned up when the stream terminates or is cancelled.
|
|
727
|
+
*
|
|
728
|
+
* The cleanup runs after `onComplete`, `onError`, or `unsubscribe()` — whichever
|
|
729
|
+
* happens first.
|
|
730
|
+
*
|
|
731
|
+
* @param resourceSupplier - Called once per subscription to acquire the resource.
|
|
732
|
+
* @param sourceFactory - Builds the source publisher from the resource.
|
|
733
|
+
* @param cleanup - Called with the resource after the stream terminates.
|
|
734
|
+
* @returns A `Flux<T>` with guaranteed resource cleanup.
|
|
735
|
+
*
|
|
736
|
+
* @example
|
|
737
|
+
* ```typescript
|
|
738
|
+
* Flux.using(
|
|
739
|
+
* () => openFile('data.txt'),
|
|
740
|
+
* file => Flux.fromIterable(file.readLines()),
|
|
741
|
+
* file => file.close()
|
|
742
|
+
* ).subscribe(line => console.log(line));
|
|
743
|
+
* ```
|
|
744
|
+
*/
|
|
745
|
+
static using<T, R>(resourceSupplier: () => R, sourceFactory: (resource: R) => Publisher<T>, cleanup: (resource: R) => void): Flux<T>;
|
|
746
|
+
/**
|
|
747
|
+
* Merges N publishers by subscribing to all of them concurrently and interleaving
|
|
748
|
+
* their items as they arrive.
|
|
749
|
+
*
|
|
750
|
+
* The stream completes when **all** sources complete.
|
|
751
|
+
* Any error from any source terminates the merged stream immediately.
|
|
752
|
+
*
|
|
753
|
+
* @param sources - Publishers to merge.
|
|
754
|
+
* @returns A `Flux<T>` that emits items from all sources concurrently.
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* Flux.merge(Flux.just(1, 2), Flux.just(3, 4)).subscribe(v => console.log(v));
|
|
759
|
+
* // 1 2 3 4 (order may vary for async sources)
|
|
760
|
+
* ```
|
|
761
|
+
*/
|
|
762
|
+
static merge<T>(...sources: Publisher<T>[]): Flux<T>;
|
|
763
|
+
/**
|
|
764
|
+
* Subscribes to all `sources` concurrently and emits the **first value** produced
|
|
765
|
+
* by any of them. All other subscriptions are cancelled immediately after the winner emits.
|
|
766
|
+
*
|
|
767
|
+
* If all sources complete without emitting a value, the result completes empty.
|
|
768
|
+
* Errors from non-winning sources are ignored once a winner is found.
|
|
769
|
+
*
|
|
770
|
+
* @param sources - Publishers to race.
|
|
771
|
+
* @returns A `Flux<T>` that emits the first value from any source.
|
|
772
|
+
*
|
|
773
|
+
* @example
|
|
774
|
+
* ```typescript
|
|
775
|
+
* // Take whichever request responds first
|
|
776
|
+
* Flux.firstWithValue(fetchFromCDN(), fetchFromOrigin())
|
|
777
|
+
* .subscribe(data => console.log(data));
|
|
778
|
+
* ```
|
|
779
|
+
*/
|
|
780
|
+
static firstWithValue<T>(...sources: Publisher<T>[]): Flux<T>;
|
|
781
|
+
/**
|
|
782
|
+
* Emits an ever-incrementing counter (0, 1, 2, …) at a fixed `ms` rate.
|
|
783
|
+
*
|
|
784
|
+
* Items are **dropped** when downstream has no outstanding demand (rather than
|
|
785
|
+
* buffered), matching Reactor's `Flux.interval` drop-on-overflow behaviour.
|
|
786
|
+
* The stream never completes on its own — cancel the subscription to stop it.
|
|
787
|
+
*
|
|
788
|
+
* @param ms - Interval duration in milliseconds.
|
|
789
|
+
* @returns An infinite `Flux<number>`.
|
|
790
|
+
*
|
|
791
|
+
* @example
|
|
792
|
+
* ```typescript
|
|
793
|
+
* Flux.interval(1000).take(3).subscribe(n => console.log(n)); // 0 1 2
|
|
794
|
+
* ```
|
|
795
|
+
*/
|
|
796
|
+
static interval(ms: number): Flux<number>;
|
|
797
|
+
/**
|
|
798
|
+
* Combines items from 2 sources positionally via `combiner`.
|
|
799
|
+
* Emits one combined value for each position; stops when the shorter source exhausts.
|
|
800
|
+
*/
|
|
801
|
+
static zip<A, B, R>(sources: [Publisher<A>, Publisher<B>], combiner: (a: A, b: B) => R): Flux<R>;
|
|
802
|
+
/**
|
|
803
|
+
* Combines items from 3 sources positionally via `combiner`.
|
|
804
|
+
*/
|
|
805
|
+
static zip<A, B, C, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>], combiner: (a: A, b: B, c: C) => R): Flux<R>;
|
|
806
|
+
/**
|
|
807
|
+
* Combines items from 4 sources positionally via `combiner`.
|
|
808
|
+
*/
|
|
809
|
+
static zip<A, B, C, D, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>, Publisher<D>], combiner: (a: A, b: B, c: C, d: D) => R): Flux<R>;
|
|
810
|
+
/**
|
|
811
|
+
* General N-source positional zip.
|
|
812
|
+
*
|
|
813
|
+
* Subscribes to each source concurrently, using a prefetch of 1 per source.
|
|
814
|
+
* Once every source has provided one item for a given position, `combiner` is
|
|
815
|
+
* called with those items and the result is emitted downstream. The stream
|
|
816
|
+
* completes when any source completes and has no buffered items left.
|
|
817
|
+
*
|
|
818
|
+
* @param sources - Publishers to zip.
|
|
819
|
+
* @param combiner - Combines one item from each source at the same position.
|
|
820
|
+
* @returns A `Flux<R>` of combined values.
|
|
821
|
+
*
|
|
822
|
+
* @example
|
|
823
|
+
* ```typescript
|
|
824
|
+
* Flux.zip([Flux.just(1, 2), Flux.just('a', 'b')], (n, s) => `${n}${s}`)
|
|
825
|
+
* .subscribe(v => console.log(v)); // '1a' '2b'
|
|
826
|
+
* ```
|
|
827
|
+
*/
|
|
828
|
+
static zip<T, R>(sources: Publisher<T>[], combiner: (...args: T[]) => R): Flux<R>;
|
|
829
|
+
/**
|
|
830
|
+
* Combines the **latest** value from each source whenever any source emits.
|
|
831
|
+
*
|
|
832
|
+
* Does not emit until all sources have produced at least one value.
|
|
833
|
+
* Continues emitting with each new item from any source, using the latest values
|
|
834
|
+
* from all others. Sources run at unbounded speed; downstream demand controls delivery.
|
|
835
|
+
*
|
|
836
|
+
* @param sources - Publishers to combine.
|
|
837
|
+
* @param combiner - Called with the latest value from each source.
|
|
838
|
+
* @returns A `Flux<R>` of combined values.
|
|
839
|
+
*
|
|
840
|
+
* @example
|
|
841
|
+
* ```typescript
|
|
842
|
+
* Flux.combineLatest([Flux.just(1, 2), Flux.just('a', 'b')], (n, s) => `${n}${s}`)
|
|
843
|
+
* .subscribe(v => console.log(v)); // '1a' '2a' '2b' (order depends on timing)
|
|
844
|
+
* ```
|
|
845
|
+
*/
|
|
846
|
+
static combineLatest<A, B, R>(sources: [Publisher<A>, Publisher<B>], combiner: (a: A, b: B) => R): Flux<R>;
|
|
847
|
+
static combineLatest<A, B, C, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>], combiner: (a: A, b: B, c: C) => R): Flux<R>;
|
|
848
|
+
static combineLatest<A, B, C, D, R>(sources: [Publisher<A>, Publisher<B>, Publisher<C>, Publisher<D>], combiner: (a: A, b: B, c: C, d: D) => R): Flux<R>;
|
|
849
|
+
static combineLatest<T, R>(sources: Publisher<T>[], combiner: (...args: T[]) => R): Flux<R>;
|
|
497
850
|
/**
|
|
498
851
|
* Transforms each item using `fn`, producing a `Flux<R>`.
|
|
499
852
|
*
|
|
@@ -992,13 +1345,17 @@ declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipeP
|
|
|
992
1345
|
*/
|
|
993
1346
|
distinctUntilChanged(comparator?: (a: T, b: T) => boolean): Flux<T>;
|
|
994
1347
|
/**
|
|
995
|
-
* Delays the delivery of each item by `ms` milliseconds
|
|
1348
|
+
* Delays the delivery of each item by `ms` milliseconds.
|
|
1349
|
+
*
|
|
1350
|
+
* Items are processed **one at a time**: the next item is requested from the source
|
|
1351
|
+
* only after the previous delayed item has been delivered downstream. This guarantees
|
|
1352
|
+
* items are spaced at least `ms` apart and that `onComplete` fires only after the last
|
|
1353
|
+
* delayed item has been delivered.
|
|
996
1354
|
*
|
|
997
|
-
*
|
|
998
|
-
* scheduled for delivery after the specified delay.
|
|
1355
|
+
* Errors are forwarded immediately without delay, cancelling any pending timer.
|
|
999
1356
|
*
|
|
1000
|
-
* @param ms - Delay in milliseconds
|
|
1001
|
-
* @returns A `Flux<T>`
|
|
1357
|
+
* @param ms - Delay in milliseconds between consecutive item deliveries.
|
|
1358
|
+
* @returns A `Flux<T>` where each item is delayed by `ms` before being forwarded.
|
|
1002
1359
|
*/
|
|
1003
1360
|
delayElements(ms: number): Flux<T>;
|
|
1004
1361
|
/**
|
|
@@ -1076,7 +1433,281 @@ declare class Flux<T> extends AbstractPipePublisher<T, Flux<T>> implements PipeP
|
|
|
1076
1433
|
* @returns A `Mono<void>` that completes once `other` completes.
|
|
1077
1434
|
*/
|
|
1078
1435
|
thenEmpty(other: Publisher<unknown>): Mono<void>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Re-subscribes to the source when the publisher returned by `fn` emits,
|
|
1438
|
+
* enabling controlled retry with strategies like exponential back-off.
|
|
1439
|
+
*
|
|
1440
|
+
* `fn` receives a `Flux<Error>` — the stream of errors emitted by each failed attempt.
|
|
1441
|
+
* Each emission from the returned publisher triggers a retry.
|
|
1442
|
+
* When the returned publisher completes or errors, the retry loop stops.
|
|
1443
|
+
*
|
|
1444
|
+
* @param fn - Receives an error stream and returns a control publisher.
|
|
1445
|
+
* @returns A `Flux<T>` with dynamic retry behaviour.
|
|
1446
|
+
*
|
|
1447
|
+
* @example
|
|
1448
|
+
* ```typescript
|
|
1449
|
+
* // Exponential back-off: wait 2^n × 100ms between retries, max 3 retries
|
|
1450
|
+
* flux.retryWhen(errors =>
|
|
1451
|
+
* errors.zipWith(Flux.range(1, 3), (_, n) => n)
|
|
1452
|
+
* .flatMap(n => Mono.delay(n * 100))
|
|
1453
|
+
* );
|
|
1454
|
+
* ```
|
|
1455
|
+
*/
|
|
1456
|
+
retryWhen(fn: (errors: Flux<Error>) => Publisher<unknown>): Flux<T>;
|
|
1457
|
+
/**
|
|
1458
|
+
* Re-subscribes to the source each time it completes normally, as controlled by
|
|
1459
|
+
* the publisher returned by `fn` (**polling** semantics).
|
|
1460
|
+
*
|
|
1461
|
+
* `fn` receives a `Flux<void>` — one emission per completion. Each emission triggers
|
|
1462
|
+
* a repeat. When the control publisher completes or errors, the loop stops.
|
|
1463
|
+
*
|
|
1464
|
+
* @param fn - Receives a completion-signal stream and returns a control publisher.
|
|
1465
|
+
* @returns A `Flux<T>` that repeats under the control of `fn`.
|
|
1466
|
+
*
|
|
1467
|
+
* @example
|
|
1468
|
+
* ```typescript
|
|
1469
|
+
* // Poll every second, stop after 5 times
|
|
1470
|
+
* fetchLatest()
|
|
1471
|
+
* .toFlux()
|
|
1472
|
+
* .repeatWhen(completes => completes.zipWith(Flux.range(1, 5), (_, n) => n)
|
|
1473
|
+
* .flatMap(() => Mono.delay(1000)));
|
|
1474
|
+
* ```
|
|
1475
|
+
*/
|
|
1476
|
+
repeatWhen(fn: (completes: Flux<void>) => Publisher<unknown>): Flux<T>;
|
|
1477
|
+
/**
|
|
1478
|
+
* Groups items by a key derived from `keyFn`, emitting a {@link GroupedFlux} per
|
|
1479
|
+
* unique key. Each `GroupedFlux` is itself a `Flux<T>` exposing the group `key`.
|
|
1480
|
+
*
|
|
1481
|
+
* The source is consumed at full speed. Items are routed to the corresponding group's
|
|
1482
|
+
* buffer and replayed to any subscriber of that group.
|
|
1483
|
+
*
|
|
1484
|
+
* @param keyFn - Extracts the group key from each item.
|
|
1485
|
+
* @returns A `Flux<GroupedFlux<K, T>>` emitting one group per unique key.
|
|
1486
|
+
*
|
|
1487
|
+
* @example
|
|
1488
|
+
* ```typescript
|
|
1489
|
+
* Flux.just(1, 2, 3, 4, 5)
|
|
1490
|
+
* .groupBy(n => n % 2 === 0 ? 'even' : 'odd')
|
|
1491
|
+
* .flatMap(group => group.collectList().map(items => ({ key: group.key, items })))
|
|
1492
|
+
* .subscribe(v => console.log(v));
|
|
1493
|
+
* // { key: 'odd', items: [1, 3, 5] }
|
|
1494
|
+
* // { key: 'even', items: [2, 4] }
|
|
1495
|
+
* ```
|
|
1496
|
+
*/
|
|
1497
|
+
groupBy<K>(keyFn: (value: T) => K): Flux<GroupedFlux<K, T>>;
|
|
1498
|
+
/**
|
|
1499
|
+
* Buffers items into arrays emitted when either `maxSize` items accumulate
|
|
1500
|
+
* **or** `ms` milliseconds elapse since the last flush — whichever comes first.
|
|
1501
|
+
*
|
|
1502
|
+
* @param maxSize - Maximum items per batch.
|
|
1503
|
+
* @param ms - Maximum time (ms) to wait before flushing a partial batch.
|
|
1504
|
+
* @returns A `Flux<T[]>` of batches.
|
|
1505
|
+
*
|
|
1506
|
+
* @example
|
|
1507
|
+
* ```typescript
|
|
1508
|
+
* // Batch up to 10 items or flush every 500ms
|
|
1509
|
+
* eventStream.bufferTimeout(10, 500).subscribe(batch => sendBatch(batch));
|
|
1510
|
+
* ```
|
|
1511
|
+
*/
|
|
1512
|
+
bufferTimeout(maxSize: number, ms: number): Flux<T[]>;
|
|
1513
|
+
/**
|
|
1514
|
+
* Samples this `Flux`, emitting the **most recent** item whenever `trigger` emits.
|
|
1515
|
+
*
|
|
1516
|
+
* If no item has arrived since the last sample, the trigger emission is ignored.
|
|
1517
|
+
* Useful for rate-limiting with external signals (scroll, resize, `requestAnimationFrame`).
|
|
1518
|
+
*
|
|
1519
|
+
* @param trigger - Controls when to sample; its value is ignored.
|
|
1520
|
+
* @returns A `Flux<T>` emitting the latest value at each trigger tick.
|
|
1521
|
+
*/
|
|
1522
|
+
sample(trigger: Publisher<unknown>): Flux<T>;
|
|
1523
|
+
/**
|
|
1524
|
+
* For each item, subscribes to `triggerFn(item)` and waits for it to emit or complete
|
|
1525
|
+
* before forwarding the item downstream (**delayUntil** semantics).
|
|
1526
|
+
*
|
|
1527
|
+
* Triggers are executed sequentially (concatMap semantics). The trigger's value
|
|
1528
|
+
* is ignored — only its timing matters.
|
|
1529
|
+
*
|
|
1530
|
+
* @param triggerFn - Returns a publisher whose first signal releases the item.
|
|
1531
|
+
* @returns A `Flux<T>` where each item is held until its trigger fires.
|
|
1532
|
+
*
|
|
1533
|
+
* @example
|
|
1534
|
+
* ```typescript
|
|
1535
|
+
* Flux.just(1, 2, 3)
|
|
1536
|
+
* .delayUntil(() => Mono.delay(100))
|
|
1537
|
+
* .subscribe(v => console.log(v)); // each item delayed 100ms
|
|
1538
|
+
* ```
|
|
1539
|
+
*/
|
|
1540
|
+
delayUntil(triggerFn: (value: T) => Publisher<unknown>): Flux<T>;
|
|
1541
|
+
/**
|
|
1542
|
+
* Recursively expands each item using `fn`, emitting both the original items and
|
|
1543
|
+
* all items produced by the expansion (**breadth-first** order).
|
|
1544
|
+
*
|
|
1545
|
+
* Useful for **pagination**: call `fn` with the current page to fetch the next,
|
|
1546
|
+
* until `fn` returns empty.
|
|
1547
|
+
*
|
|
1548
|
+
* @param fn - Receives an item; returns a publisher of zero or more new items to expand.
|
|
1549
|
+
* @returns A `Flux<T>` of all original and expanded items.
|
|
1550
|
+
*
|
|
1551
|
+
* @example
|
|
1552
|
+
* ```typescript
|
|
1553
|
+
* // Fetch all pages recursively
|
|
1554
|
+
* fetchPage(1)
|
|
1555
|
+
* .toFlux()
|
|
1556
|
+
* .expand(page => page.hasNext ? fetchPage(page.nextId).toFlux() : Flux.empty())
|
|
1557
|
+
* .subscribe(page => process(page));
|
|
1558
|
+
* ```
|
|
1559
|
+
*/
|
|
1560
|
+
expand(fn: (value: T) => Publisher<T>): Flux<T>;
|
|
1561
|
+
/**
|
|
1562
|
+
* Recursively expands each item using `fn`, emitting both the original items and
|
|
1563
|
+
* all items produced by the expansion (**depth-first** order).
|
|
1564
|
+
*
|
|
1565
|
+
* Unlike {@link expand} (breadth-first), each item's children are emitted immediately
|
|
1566
|
+
* after the item itself, before any sibling items are processed. This mirrors a
|
|
1567
|
+
* recursive pre-order tree traversal.
|
|
1568
|
+
*
|
|
1569
|
+
* @param fn - Receives an item; returns a publisher of zero or more new items to expand.
|
|
1570
|
+
* @returns A `Flux<T>` of all original and expanded items in depth-first order.
|
|
1571
|
+
*
|
|
1572
|
+
* @example
|
|
1573
|
+
* ```typescript
|
|
1574
|
+
* // Tree: 1 → [2, 3], 2 → [4, 5], others → empty
|
|
1575
|
+
* Flux.just(1)
|
|
1576
|
+
* .expandDeep(n =>
|
|
1577
|
+
* n === 1 ? Flux.just(2, 3) :
|
|
1578
|
+
* n === 2 ? Flux.just(4, 5) :
|
|
1579
|
+
* Flux.empty()
|
|
1580
|
+
* )
|
|
1581
|
+
* .subscribe(v => console.log(v));
|
|
1582
|
+
* // 1 2 4 5 3 (depth-first pre-order)
|
|
1583
|
+
* ```
|
|
1584
|
+
*/
|
|
1585
|
+
expandDeep(fn: (value: T) => Publisher<T>): Flux<T>;
|
|
1586
|
+
/**
|
|
1587
|
+
* Pairs each item with the time elapsed (in ms) since the **previous** item
|
|
1588
|
+
* (or since subscription for the first item).
|
|
1589
|
+
*
|
|
1590
|
+
* @returns A `Flux<[number, T]>` where the first element is elapsed milliseconds.
|
|
1591
|
+
*
|
|
1592
|
+
* @example
|
|
1593
|
+
* ```typescript
|
|
1594
|
+
* Flux.interval(100).take(3).elapsed().subscribe(([ms, n]) => console.log(ms, n));
|
|
1595
|
+
* // ~100 0 ~100 1 ~100 2
|
|
1596
|
+
* ```
|
|
1597
|
+
*/
|
|
1598
|
+
elapsed(): Flux<[number, T]>;
|
|
1599
|
+
/**
|
|
1600
|
+
* Attaches a `Date.now()` timestamp (in ms since epoch) to each item.
|
|
1601
|
+
*
|
|
1602
|
+
* @returns A `Flux<[number, T]>` where the first element is the Unix timestamp in ms.
|
|
1603
|
+
*/
|
|
1604
|
+
timestamp(): Flux<[number, T]>;
|
|
1605
|
+
/**
|
|
1606
|
+
* Wraps each signal (next, error, complete) into a {@link Signal} data object,
|
|
1607
|
+
* emitting them all as `onNext` items on a `Flux<Signal<T>>`.
|
|
1608
|
+
*
|
|
1609
|
+
* After materializing, the resulting `Flux` always completes normally (errors become
|
|
1610
|
+
* `Signal.error` items rather than `onError` signals).
|
|
1611
|
+
* Use {@link dematerialize} to convert back.
|
|
1612
|
+
*
|
|
1613
|
+
* @returns A `Flux<Signal<T>>` where every event is represented as a data item.
|
|
1614
|
+
*/
|
|
1615
|
+
materialize(): Flux<Signal<T>>;
|
|
1616
|
+
/**
|
|
1617
|
+
* Unwraps a `Flux<Signal<R>>` back into a regular `Flux<R>`, restoring
|
|
1618
|
+
* `error` and `complete` signals from their materialized form.
|
|
1619
|
+
*
|
|
1620
|
+
* This is the inverse of {@link materialize}.
|
|
1621
|
+
*
|
|
1622
|
+
* @returns A `Flux<R>` with signals restored from the `Signal` wrappers.
|
|
1623
|
+
*/
|
|
1624
|
+
dematerialize<R>(this: Flux<Signal<R>>): Flux<R>;
|
|
1625
|
+
/**
|
|
1626
|
+
* Buffers all upstream items regardless of downstream demand, delivering them
|
|
1627
|
+
* when demand becomes available.
|
|
1628
|
+
*
|
|
1629
|
+
* If `maxSize` is exceeded, an overflow error is signalled downstream.
|
|
1630
|
+
*
|
|
1631
|
+
* @param maxSize - Maximum buffer capacity (default: unbounded).
|
|
1632
|
+
* @returns A `Flux<T>` with explicit backpressure buffering.
|
|
1633
|
+
*/
|
|
1634
|
+
onBackpressureBuffer(maxSize?: number): Flux<T>;
|
|
1635
|
+
/**
|
|
1636
|
+
* Drops upstream items that arrive when downstream has no outstanding demand.
|
|
1637
|
+
*
|
|
1638
|
+
* An optional `onDrop` callback is invoked for each dropped item.
|
|
1639
|
+
*
|
|
1640
|
+
* @param onDrop - Optional callback called with each dropped item.
|
|
1641
|
+
* @returns A `Flux<T>` with drop backpressure strategy.
|
|
1642
|
+
*/
|
|
1643
|
+
onBackpressureDrop(onDrop?: (value: T) => void): Flux<T>;
|
|
1644
|
+
/**
|
|
1645
|
+
* Keeps only the **latest** upstream item when downstream has no demand;
|
|
1646
|
+
* older buffered items are overwritten as new ones arrive.
|
|
1647
|
+
*
|
|
1648
|
+
* @returns A `Flux<T>` with latest-value backpressure strategy.
|
|
1649
|
+
*/
|
|
1650
|
+
onBackpressureLatest(): Flux<T>;
|
|
1651
|
+
/**
|
|
1652
|
+
* Requests items from upstream in batches of `n`, replenishing when 75% of
|
|
1653
|
+
* the batch has been consumed (**prefetch** / **limitRate** semantics).
|
|
1654
|
+
*
|
|
1655
|
+
* Prevents requesting all items at once from expensive sources.
|
|
1656
|
+
*
|
|
1657
|
+
* @param n - Prefetch batch size.
|
|
1658
|
+
* @returns A `Flux<T>` with controlled upstream demand.
|
|
1659
|
+
*/
|
|
1660
|
+
limitRate(n: number): Flux<T>;
|
|
1661
|
+
/**
|
|
1662
|
+
* Filters items by runtime type, passing only items that are instances of `constructor`.
|
|
1663
|
+
*
|
|
1664
|
+
* @typeParam R - The target subtype.
|
|
1665
|
+
* @param constructor - The class/constructor to filter by.
|
|
1666
|
+
* @returns A `Flux<R>` containing only items that pass `instanceof`.
|
|
1667
|
+
*
|
|
1668
|
+
* @example
|
|
1669
|
+
* ```typescript
|
|
1670
|
+
* class Cat { meow() {} }
|
|
1671
|
+
* class Dog { bark() {} }
|
|
1672
|
+
* Flux.just(new Cat(), new Dog(), new Cat())
|
|
1673
|
+
* .ofType(Cat)
|
|
1674
|
+
* .subscribe(cat => cat.meow());
|
|
1675
|
+
* ```
|
|
1676
|
+
*/
|
|
1677
|
+
ofType<R extends T>(constructor: new (...args: unknown[]) => R): Flux<R>;
|
|
1678
|
+
/**
|
|
1679
|
+
* Applies a reusable operator function `fn` to this `Flux`, deferred per subscription.
|
|
1680
|
+
*
|
|
1681
|
+
* `fn` receives this `Flux<T>` (as a `Publisher<T>`) and returns a new `Publisher<R>`.
|
|
1682
|
+
* The transformation is re-evaluated on each `subscribe()` call (deferred assembly).
|
|
1683
|
+
*
|
|
1684
|
+
* @param fn - Operator function to apply.
|
|
1685
|
+
* @returns A `Flux<R>` produced by `fn`.
|
|
1686
|
+
*
|
|
1687
|
+
* @example
|
|
1688
|
+
* ```typescript
|
|
1689
|
+
* const retryThrice = <T>(source: Publisher<T>) => Flux.from(source).retry(3);
|
|
1690
|
+
* Flux.just(1, 2).transformDeferred(retryThrice).subscribe(v => console.log(v));
|
|
1691
|
+
* ```
|
|
1692
|
+
*/
|
|
1693
|
+
transformDeferred<R>(fn: (flux: Publisher<T>) => Publisher<R>): Flux<R>;
|
|
1079
1694
|
}
|
|
1695
|
+
/**
|
|
1696
|
+
* A `Flux<T>` tagged with a group `key`.
|
|
1697
|
+
*
|
|
1698
|
+
* Produced by {@link Flux#groupBy} — subscribe to it exactly like any `Flux<T>`;
|
|
1699
|
+
* the extra `key` property identifies which group this stream belongs to.
|
|
1700
|
+
*
|
|
1701
|
+
* Implemented as a plain type intersection rather than a subclass: the runtime
|
|
1702
|
+
* object is an ordinary `Flux<T>` with a `key` property attached via
|
|
1703
|
+
* `Object.assign`, so no extra prototype chain is required.
|
|
1704
|
+
*
|
|
1705
|
+
* @typeParam K - The type of the group key.
|
|
1706
|
+
* @typeParam T - The type of items in the group.
|
|
1707
|
+
*/
|
|
1708
|
+
type GroupedFlux<K, T> = Flux<T> & {
|
|
1709
|
+
readonly key: K;
|
|
1710
|
+
};
|
|
1080
1711
|
|
|
1081
1712
|
/**
|
|
1082
1713
|
* A cold publisher of 0 or 1 items with full backpressure support.
|
|
@@ -1187,6 +1818,61 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
1187
1818
|
* @returns A lazy `Mono<T>`.
|
|
1188
1819
|
*/
|
|
1189
1820
|
static defer<T>(factory: () => Mono<T>): Mono<T>;
|
|
1821
|
+
/**
|
|
1822
|
+
* Alias for {@link Mono.generate} — imperative push interface.
|
|
1823
|
+
*
|
|
1824
|
+
* The generator receives a {@link Sink} and should call exactly one of:
|
|
1825
|
+
* `sink.next(value)`, `sink.error(err)`, or `sink.complete()`.
|
|
1826
|
+
*
|
|
1827
|
+
* @param generator - Function that drives the `Mono` via the provided `Sink<T>`.
|
|
1828
|
+
* @returns A cold `Mono<T>`.
|
|
1829
|
+
*/
|
|
1830
|
+
static create<T>(generator: (sink: Sink<T>) => void): Mono<T>;
|
|
1831
|
+
/**
|
|
1832
|
+
* Creates a `Mono<number>` that emits `0` after `ms` milliseconds then completes.
|
|
1833
|
+
*
|
|
1834
|
+
* Useful for introducing timed delays in reactive pipelines.
|
|
1835
|
+
*
|
|
1836
|
+
* @param ms - The delay in milliseconds.
|
|
1837
|
+
* @returns A `Mono<number>` that emits `0` after the delay.
|
|
1838
|
+
*
|
|
1839
|
+
* @example
|
|
1840
|
+
* ```typescript
|
|
1841
|
+
* Mono.delay(500).flatMap(() => Mono.just('hello')).subscribe(v => console.log(v));
|
|
1842
|
+
* ```
|
|
1843
|
+
*/
|
|
1844
|
+
static delay(ms: number): Mono<number>;
|
|
1845
|
+
/**
|
|
1846
|
+
* Creates a `Mono<T>` from a synchronous, potentially-throwing factory function.
|
|
1847
|
+
*
|
|
1848
|
+
* The factory is called **lazily** at subscription time (not at assembly time).
|
|
1849
|
+
* If the factory throws, the exception is forwarded as `onError`.
|
|
1850
|
+
*
|
|
1851
|
+
* @param fn - Synchronous factory invoked once per subscription.
|
|
1852
|
+
* @returns A cold `Mono<T>`.
|
|
1853
|
+
*
|
|
1854
|
+
* @example
|
|
1855
|
+
* ```typescript
|
|
1856
|
+
* Mono.fromCallable(() => JSON.parse(rawJson)).subscribe(v => console.log(v));
|
|
1857
|
+
* ```
|
|
1858
|
+
*/
|
|
1859
|
+
static fromCallable<T>(fn: () => T): Mono<T>;
|
|
1860
|
+
/**
|
|
1861
|
+
* Races multiple `Mono`s — emits the first value to arrive, cancelling the rest.
|
|
1862
|
+
*
|
|
1863
|
+
* If a source completes without emitting, it is excluded from the race.
|
|
1864
|
+
* If **all** sources complete empty, the resulting `Mono` also completes empty.
|
|
1865
|
+
* If any source errors before another source emits, the error is propagated.
|
|
1866
|
+
*
|
|
1867
|
+
* @param sources - One or more `Mono<T>` sources to race.
|
|
1868
|
+
* @returns A `Mono<T>` that emits the first available value.
|
|
1869
|
+
*
|
|
1870
|
+
* @example
|
|
1871
|
+
* ```typescript
|
|
1872
|
+
* Mono.firstWithValue(slow, fast).subscribe(v => console.log(v)); // fast's value
|
|
1873
|
+
* ```
|
|
1874
|
+
*/
|
|
1875
|
+
static firstWithValue<T>(...sources: Mono<T>[]): Mono<T>;
|
|
1190
1876
|
/**
|
|
1191
1877
|
* Transforms the emitted value using `fn`, producing a `Mono<R>`.
|
|
1192
1878
|
*
|
|
@@ -1326,6 +2012,122 @@ declare class Mono<T> extends AbstractPipePublisher<T, Mono<T>> implements PipeP
|
|
|
1326
2012
|
* @returns A `Mono<boolean>`.
|
|
1327
2013
|
*/
|
|
1328
2014
|
hasElement(): Mono<boolean>;
|
|
2015
|
+
/**
|
|
2016
|
+
* Side effect executed when the `Mono` emits its value.
|
|
2017
|
+
*
|
|
2018
|
+
* Does **not** affect the emitted value or stream lifecycle.
|
|
2019
|
+
* Exceptions thrown by `fn` are forwarded as `onError`.
|
|
2020
|
+
*
|
|
2021
|
+
* @param fn - Called with the emitted value.
|
|
2022
|
+
* @returns A `Mono<T>` with the side effect attached.
|
|
2023
|
+
*
|
|
2024
|
+
* @example
|
|
2025
|
+
* ```typescript
|
|
2026
|
+
* Mono.just(42).doOnSuccess(v => console.log('got', v)).subscribe();
|
|
2027
|
+
* ```
|
|
2028
|
+
*/
|
|
2029
|
+
doOnSuccess(fn: (value: T) => void): Mono<T>;
|
|
2030
|
+
/**
|
|
2031
|
+
* Converts a terminal error into a normal `onComplete` signal.
|
|
2032
|
+
*
|
|
2033
|
+
* If a `predicate` is supplied, only errors for which the predicate returns `true`
|
|
2034
|
+
* are swallowed; others are re-propagated as-is.
|
|
2035
|
+
*
|
|
2036
|
+
* @param predicate - Optional filter; when absent all errors are converted.
|
|
2037
|
+
* @returns A `Mono<T>` that completes rather than errors (when predicate matches).
|
|
2038
|
+
*
|
|
2039
|
+
* @example
|
|
2040
|
+
* ```typescript
|
|
2041
|
+
* Mono.error(new Error('oops')).onErrorComplete().subscribe(undefined, undefined, () => console.log('done'));
|
|
2042
|
+
* ```
|
|
2043
|
+
*/
|
|
2044
|
+
onErrorComplete(predicate?: (e: Error) => boolean): Mono<T>;
|
|
2045
|
+
/**
|
|
2046
|
+
* Ignores any value emitted by this `Mono` and, upon normal completion,
|
|
2047
|
+
* emits `value` instead.
|
|
2048
|
+
*
|
|
2049
|
+
* Errors from the source are propagated unchanged.
|
|
2050
|
+
*
|
|
2051
|
+
* @param value - The value to emit after this `Mono` completes.
|
|
2052
|
+
* @returns A `Mono<R>` that emits `value` on source completion.
|
|
2053
|
+
*
|
|
2054
|
+
* @example
|
|
2055
|
+
* ```typescript
|
|
2056
|
+
* Mono.just('ignored').thenReturn(42).subscribe(v => console.log(v)); // 42
|
|
2057
|
+
* ```
|
|
2058
|
+
*/
|
|
2059
|
+
thenReturn<R>(value: R): Mono<R>;
|
|
2060
|
+
/**
|
|
2061
|
+
* Delays delivery of the emitted value by `ms` milliseconds.
|
|
2062
|
+
*
|
|
2063
|
+
* The delay is introduced **after** the source emits; completion and errors
|
|
2064
|
+
* are forwarded without delay.
|
|
2065
|
+
*
|
|
2066
|
+
* @param ms - Delay in milliseconds.
|
|
2067
|
+
* @returns A `Mono<T>` whose value arrives `ms` milliseconds later.
|
|
2068
|
+
*
|
|
2069
|
+
* @example
|
|
2070
|
+
* ```typescript
|
|
2071
|
+
* Mono.just('hello').delayElement(200).subscribe(v => console.log(v));
|
|
2072
|
+
* ```
|
|
2073
|
+
*/
|
|
2074
|
+
delayElement(ms: number): Mono<T>;
|
|
2075
|
+
/**
|
|
2076
|
+
* Holds the emitted value until a trigger publisher (returned by `triggerFn`) emits
|
|
2077
|
+
* or completes, then forwards the value downstream.
|
|
2078
|
+
*
|
|
2079
|
+
* If the trigger errors, the error is propagated and the value is discarded.
|
|
2080
|
+
* If the source is empty, completes immediately without invoking `triggerFn`.
|
|
2081
|
+
*
|
|
2082
|
+
* @param triggerFn - Receives the emitted value and returns a trigger `Publisher`.
|
|
2083
|
+
* @returns A `Mono<T>` that emits after the trigger fires.
|
|
2084
|
+
*
|
|
2085
|
+
* @example
|
|
2086
|
+
* ```typescript
|
|
2087
|
+
* Mono.just(42).delayUntil(() => Mono.delay(300)).subscribe(v => console.log(v));
|
|
2088
|
+
* ```
|
|
2089
|
+
*/
|
|
2090
|
+
delayUntil(triggerFn: (value: T) => Publisher<unknown>): Mono<T>;
|
|
2091
|
+
/**
|
|
2092
|
+
* Falls back to `other` if this `Mono` completes without emitting a value (empty).
|
|
2093
|
+
*
|
|
2094
|
+
* If this `Mono` emits a value or errors, `other` is never subscribed to.
|
|
2095
|
+
*
|
|
2096
|
+
* @param other - The fallback `Mono<T>` to subscribe to when the source is empty.
|
|
2097
|
+
* @returns A `Mono<T>` that emits from `other` when the source is empty.
|
|
2098
|
+
*
|
|
2099
|
+
* @example
|
|
2100
|
+
* ```typescript
|
|
2101
|
+
* Mono.empty<number>().or(Mono.just(99)).subscribe(v => console.log(v)); // 99
|
|
2102
|
+
* ```
|
|
2103
|
+
*/
|
|
2104
|
+
or(other: Mono<T>): Mono<T>;
|
|
2105
|
+
/**
|
|
2106
|
+
* Re-subscribes to this `Mono` on error, using a control publisher to decide
|
|
2107
|
+
* whether and when to retry.
|
|
2108
|
+
*
|
|
2109
|
+
* Each time the source errors, the error is pushed to the control stream returned
|
|
2110
|
+
* by `fn`. If that stream emits any item, the source is re-subscribed. If it
|
|
2111
|
+
* completes or errors, that terminal signal is forwarded downstream.
|
|
2112
|
+
*
|
|
2113
|
+
* @param fn - Receives a `Flux<Error>` of upstream errors; returns a control publisher.
|
|
2114
|
+
* @returns A `Mono<T>` that retries according to the control signal.
|
|
2115
|
+
*
|
|
2116
|
+
* @example
|
|
2117
|
+
* ```typescript
|
|
2118
|
+
* Mono.error(new Error('boom'))
|
|
2119
|
+
* .retryWhen(errors => errors.take(3))
|
|
2120
|
+
* .subscribe(undefined, e => console.error(e));
|
|
2121
|
+
* ```
|
|
2122
|
+
*/
|
|
2123
|
+
retryWhen(fn: (errors: Flux<Error>) => Publisher<unknown>): Mono<T>;
|
|
2124
|
+
/**
|
|
2125
|
+
* Alias for {@link Mono#toPromise} — returns a `Promise<T | null>` that resolves
|
|
2126
|
+
* with the emitted value (or `null` if the `Mono` is empty).
|
|
2127
|
+
*
|
|
2128
|
+
* @returns A `Promise<T | null>`.
|
|
2129
|
+
*/
|
|
2130
|
+
toFuture(): Promise<T | null>;
|
|
1329
2131
|
/**
|
|
1330
2132
|
* Subscribes to this `Mono` and returns a `Promise<T | null>`.
|
|
1331
2133
|
*
|
|
@@ -1555,4 +2357,4 @@ declare const Sinks: {
|
|
|
1555
2357
|
};
|
|
1556
2358
|
};
|
|
1557
2359
|
|
|
1558
|
-
export { type CancellableScheduler, Flux, Mono, type Publisher, type Scheduler, Schedulers, type Sink, type SinkPublisher, Sinks, type Subscriber, type Subscription };
|
|
2360
|
+
export { type CancellableScheduler, Flux, type FluxSink, type GroupedFlux, Mono, type Publisher, type Scheduler, Schedulers, Signal, type Sink, type SinkPublisher, Sinks, type Subscriber, type Subscription };
|