我有一个可观察到的api请求,基本上我在事件连接失败/错误时添加了retryWhen
。这样做时,我想在请求抛出错误时调度另一个操作(不通知用户系统正在重试。)
//.... export const saveArticle1 = (action$, state$) => action$.pipe( ofType(AUTO_SAVE_ARTICLE_READY), withLatestFrom(state$, (a, b) => b), switchMap(({ article, }) => { const payload = getArticlePayload(article); return ajax.patch(`/api/article/${article.id}`, payload, { 'Content-Type': 'application/json' }).pipe( flatMap(({ response }) => of({ type: ARTICLE_AUTO_SAVED, value: response, })), retryWhen(errors => errors.pipe( // TODO: I try to concat or merge observable here but no luck delay(1000), take(60), ), ), catchError((ex) => { articleSaveFailureAlert(); return showErrorNotification('Api Error. Unable to save this article.')(ex); }), ); }), );
[
retryWhen
中分派另一个动作的最佳方法是什么?还是有另一种方法可以实现这一目标?
我有一个可观察的api请求,基本上我在事件连接失败/错误时添加了retryWhen。这样做时,我想调度另一个操作(不通知用户系统正在重试。)...
您可以在递归循环的停止条件下使用尝试次数大于允许的最大尝试次数的循环。然后,您可以将“重试”操作的单个可观察值与可观察到的补丁连接起来。如果您将代码段修改为将maxAttempts
更改为小于5的数字,则会看到正在发出“失败”操作。