我正在嘗試使用C#觀察值編寫重試機(jī)制。重試具有重試次數(shù)和重試間隔重試應(yīng)執(zhí)行“ OnExecute”方法。在每個異常上,它將執(zhí)行“ OnCatch”方法。這是我嘗試做的事情:public static IObservable<T> Retry(GenericRetryExecutorRequest<T> request){ var source = Observable.Timer(TimeSpan.Zero, request.Interval) .Select(item => { return request.GenericRetryActions.OnExecute(); }); var retryObservable = source .Retry(request.RetryCount) .Catch(source); return retryObservable;}public class GenericRetryExecutorRequest<T>{ public int RetryCount { get; set; } = 3; public TimeSpan Interval { get; set; } = new TimeSpan(0,0,0,5); public IGenericRetryActions<T> GenericRetryActions { get; set; }}public interface IGenericRetryActions<out T>{ T OnExecute(); void OnCatch();}不幸的是-它表現(xiàn)不佳:OnCatch拋出異常時,我不知道如何執(zhí)行。我嘗試了很多方法都沒有成功。OnExecute 似乎不會重復(fù)執(zhí)行(以請求間隔),以防它引發(fā)異常。
- 1 回答
- 0 關(guān)注
- 166 瀏覽
添加回答
舉報
0/150
提交
取消