0

我有以下示例:

const result = http.get('http://google.com')

               .switchMap(() => 'http://example.com')

               // This retry should retry only example.com
               .retryWhen(error => 
                    (error instanceof Response && error.status == 429) ?
                     Observable.timeout(5000) : Observable.throw(error))

               // This retry should retry google.com
               .retryWhen(error => Observable.timeout(5000))

我想要一个 retryWhen ,它只会重试他的直系父母。然后如果出现全局错误,我将重试整个序列。RxJS 5 有简单的方法吗?

UPD:这些只是例子。实际上情况更复杂,我只需要一个想法。

4

1 回答 1

1

你只需要把retryWhen里面switchMap

const inner = http.get('http://example.com')
      // This retry should retry only example.com
      .retryWhen(error => 
       (error instanceof Response && error.status == 429) ?
        Observable.timer(5000) : Observable.throw(error))

const outer = http.get('http://google.com')
  .switchMap(() => inner)
  // This retry should retry google.com
  .retryWhen(error => Observable.timeout(5000))
于 2017-03-29T16:26:29.607 回答