Write an Rx “RetryAfter” extension method

前端 未结 6 938
花落未央
花落未央 2020-11-27 16:00

In the book IntroToRx the author suggest to write a \"smart\" retry for I/O which retry an I/O request, like a network request, after a period of time.

Here is the e

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 17:03

    Here's the one I'm using:

    public static IObservable DelayedRetry(this IObservable src, TimeSpan delay)
    {
        Contract.Requires(src != null);
        Contract.Ensures(Contract.Result>() != null);
    
        if (delay == TimeSpan.Zero) return src.Retry();
        return src.Catch(Observable.Timer(delay).SelectMany(x => src).Retry());
    }
    

提交回复
热议问题