Table of Contents

Class RetryOperator

Namespace
RxSharp.Operators
Assembly
RxSharp.dll

Extension methods implementing the retry operator.

public static class RetryOperator
Inheritance
System.Object
RetryOperator

Remarks

rxjs's retry accepts either a plain retry count or a single RetryConfig object combining count, delay (a fixed number of milliseconds, or a per-error notifier-returning function), and resetOnSuccess. C# has no object-literal equivalent that reads as naturally as rxjs's, so this port splits that one config object into two overloads instead: the original Retry<T>(Observable<T>, int, TimeSpan?, IScheduler?, bool) (count + an optional fixed TimeSpan delay + resetOnSuccess), and Retry<T, TNotification>(Observable<T>, Func<Exception, int, Observable<TNotification>>, int, bool) (count + a per-error notifier-selector delay + resetOnSuccess) for the function-based delay form. Both funnel into the same private RxSharp.Operators.RetryOperator.RetryCore``2(RxSharp.Observable{``0},System.Int32,System.Boolean,System.Nullable{Func{Exception,System.Int32,RxSharp.Observable{``1}}}) implementation.

Methods

Retry<T>(Observable<T>, int, TimeSpan?, IScheduler?, bool)

Resubscribes to source whenever it errors, up to count times, instead of forwarding the error downstream. Once the retry budget is exhausted, the most recent error is forwarded via OnError as usual. Values emitted before a failed attempt are still forwarded downstream; a retry only affects what happens after the error.

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

Parameters

source Observable<T>

The source sequence to retry on error.

count int

The maximum number of resubscriptions to attempt after an error. Defaults to int.MaxValue (effectively unlimited retries). A value of zero or less disables retrying entirely, and source is returned unchanged.

delay TimeSpan?

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

scheduler IScheduler

The scheduler used to time delay, if provided.

resetOnSuccess bool

If true, the retry counter resets to zero the moment source emits its first value after a resubscription — so a long-running stream that errors only intermittently never exhausts its retry budget from historical errors. Defaults to false, matching rxjs.

Returns

Observable<T>

An observable that mirrors source, retrying on error as described above.

Type Parameters

T

The type of values emitted by source.

Remarks

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

Retry<T, TNotification>(Observable<T>, Func<Exception, int, Observable<TNotification>>, int, bool)

Resubscribes to source whenever it errors, up to count times, 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> Retry<T, TNotification>(this Observable<T> source, Func<Exception, int, Observable<TNotification>> delaySelector, int count = null, bool resetOnSuccess = false)

Parameters

source Observable<T>

The source sequence to retry on error.

delaySelector Func<Exception, int, Observable<TNotification>>

A function, called with the error that just occurred and the current 1-based retry attempt number, that returns an observable whose first emission triggers the resubscription.

count int

The maximum number of resubscriptions to attempt after an error. Defaults to int.MaxValue.

resetOnSuccess bool

If true, the retry counter resets to zero the moment source emits its first value after a resubscription. Defaults to false, matching rxjs.

Returns

Observable<T>

An observable that mirrors source, retrying on error 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 RetryConfig.delay. delaySelector is called with the error that just occurred and the current 1-based retry attempt number, and must return a notifier observable: its first emission triggers the resubscription, an early completion (without ever emitting) completes the whole sequence instead of retrying, and an error is forwarded downstream via OnError in place of the original error. If delaySelector itself throws, that exception is forwarded via OnError too.