使用retry的mergeMap从点开始运行重试失败而没有重新开始

时间:2019-06-23 13:12:53

标签: angular typescript rxjs

我有N个网址,我不知道它的数量(直到到达停止状态)

这是我的用法:

 from(observableUrls)
  .pipe(
    mergeMap(url => callHttpService(url) , 4),
    retryWhen(
       // what is the algorithm or suggestion how to?
    )
  ).subscribe( result => {
     // doing some stuff with my results
  });

如果某些URL失败,怎么执行重试而不重新运行的算法或建议是什么。

StackBlitz: https://angular-w5t15m.stackblitz.io

1 个答案:

答案 0 :(得分:0)

您应在单个retryWhen的可观察管道中使用callHttpService(url),如下所示:

from(observableUrls)
              .pipe(
                mergeMap(url => callHttpService(url)
                                    .pipe(
                                      retryWhen(
                                        // use your retryWhen logic here
                                      )
                                    ) , 4)                
              ).subscribe( result => {
                // doing some stuff with my results
              });

在内部Observable(retryWhen)的Observable管道中包含callHttpService(url)将确保根据retryWhen逻辑仅重试该可观察项。 希望对您有所帮助。