码迷,mamicode.com
首页 > Web开发 > 详细

[RxJS 6] The Retry RxJs Error Handling Strategy

时间:2018-07-08 10:35:43      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:pip   ons   obs   erro   bsp   pre   class   obj   rate   

When we want to handle error observable in RxJS v6+, we can use ‘retryWhen‘ and ‘delayWhen‘:

const courses$: Observable<Counse[]> = http$
    .pipe(
        tap(() => console.log("HTTP request")),
        map(res => Object.values(res[‘payload‘])),
        shareReplay(), // avoid using async pipe multi times causing multi network request
        retryWhen(errors => errors.pipe(
           delayWhen(() => timer(2000)) // wait 2s after the error observable happens    
        ))
)

 

[RxJS 6] The Retry RxJs Error Handling Strategy

标签:pip   ons   obs   erro   bsp   pre   class   obj   rate   

原文地址:https://www.cnblogs.com/Answer1215/p/9278994.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!