New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing RetryUntil/RetryWhen #449
Comments
You could emulate public static IObservable<T> RetryWhen<T, U>(this IObservable<T> source,
Func<IObservable<Exception>, IObservable<U>> handler)
{
return Observable.Defer(() =>
{
var errorSignal = new Subject<Exception>();
var retrySignal = handler(errorSignal);
var sources = new BehaviorSubject<IObservable<T>>(source);
return Observable.Using(
() => retrySignal.Select(s => source).Subscribe(sources),
r => sources.Select(src =>
src.Do(v => { }, e => errorSignal.OnNext(e), () => errorSignal.OnCompleted())
.OnErrorResumeNext(Observable.Empty<T>())
).Concat()
)
;
});
} Example: int[] count = { 3 };
Observable.Defer(() =>
{
if (count[0]-- == 0)
{
return Observable.Return("Success");
}
return Observable.Throw<String>(new Exception());
})
.RetryWhen(
f => f.SelectMany(e =>
{
Console.WriteLine("Retrying...");
return Observable.Timer(TimeSpan.FromSeconds(1));
})
)
.Subscribe(Console.WriteLine, Console.WriteLine, () => Console.WriteLine("Done"));
Thread.Sleep(5000);
Some ReactiveX libraries evolve faster than others and not all features are available everywhere. With C# and extension methods, you are in a much better position to create your own custom operators. |
thx for explaining |
PR #486 adds a |
yup thx |
i tried to implement RetryUntil in my code with:
but that gives me an invalidOperationException: "Sequence Contains no Elements". if end publishes a value.
Is there any way i can get a TaskCancellation Exception.
Also RetryWhen is missing from Rx.net and id like to retry after some amount of time rather than instant. How can i do that without RetryWhen?
Is there any reason the above methods are not included? / may i submit a pr?
The text was updated successfully, but these errors were encountered: