Table of Contents

Class RepeatOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Extension methods implementing the repeat operator.

public static class RepeatOperator
Inheritance
System.Object
RepeatOperator

Remarks

rxjs's repeat accepts either a plain repeat count or a single RepeatConfig object combining count and delay (a fixed number of milliseconds, or a per-cycle notifier-returning function). As with RetryOperator, this port splits that one config object into two overloads instead of introducing a config type: the original Repeat<T>(Observable<T>, int, TimeSpan?, IScheduler?) (count + an optional fixed TimeSpan delay), and Repeat<T, TNotification>(Observable<T>, Func<int, Observable<TNotification>>, int) (count + a per-cycle notifier-selector delay). rxjs's RepeatConfig has no resetOnSuccess equivalent — that option only exists on retry, since repeat has no error/success distinction to reset on.

Methods

Repeat<T>(Observable<T>, int, TimeSpan?, IScheduler?)

Resubscribes to source whenever it completes, up to count times in total, instead of forwarding the completion downstream. Once the repeat budget is exhausted, completion is forwarded via OnCompleted as usual. Unlike Retry, an error from source is never retried — it is forwarded via OnError immediately, ending the sequence.

public static Observable<T> Repeat<T>(this Observable<T> source, int count = null, TimeSpan? delay = null, IScheduler? scheduler = null)

Parameters

source Observable<T>

The source sequence to repeat on completion.

count int

The total number of times to subscribe to source. Defaults to int.MaxValue (effectively repeating forever). A value of zero or less returns an already-completed, empty observable without ever subscribing to source — unlike Retry<T>(Observable<T>, int, TimeSpan?, IScheduler?, bool)'s zero-or-less handling, which still subscribes once.

delay TimeSpan?

An optional fixed delay to wait before each resubscription. If null (the default), resubscription happens immediately after completion.

scheduler IScheduler

The scheduler used to time delay, if provided.

Returns

Observable<T>

An observable that mirrors source, resubscribing on completion as described above.

Type Parameters

T

The type of values emitted by source.

Remarks

This overload covers rxjs's RepeatConfig with a plain numeric or omitted delay (or none at all). For a per-cycle notifier-observable delay, use Repeat<T, TNotification>(Observable<T>, Func<int, Observable<TNotification>>, int) instead.

Repeat<T, TNotification>(Observable<T>, Func<int, Observable<TNotification>>, int)

Resubscribes to source whenever it completes, up to count times in total, but waits for the observable returned by delaySelector to emit before each resubscription instead of resubscribing immediately or after a fixed delay.

public static Observable<T> Repeat<T, TNotification>(this Observable<T> source, Func<int, Observable<TNotification>> delaySelector, int count = null)

Parameters

source Observable<T>

The source sequence to repeat on completion.

delaySelector Func<int, Observable<TNotification>>

A function, called with the current 1-based cycle count, that returns an observable whose first emission triggers the resubscription.

count int

The total number of times to subscribe to source. Defaults to int.MaxValue.

Returns

Observable<T>

An observable that mirrors source, resubscribing on completion as described above.

Type Parameters

T

The type of values emitted by source.

TNotification

The element type of the observable returned by delaySelector; only its emissions/termination matter, not the values themselves.

Remarks

This is the function-based form of rxjs's RepeatConfig.delay. delaySelector is called with the current 1-based cycle count (how many times source has completed so far) and must return a notifier observable: its first emission triggers the resubscription, and an early completion (without ever emitting) completes the whole sequence instead of repeating. If delaySelector itself throws, or the notifier it returns errors, that exception is forwarded via OnError.