RxJS: Observable.never() keeps like subscription

前端 未结 2 2026
天命终不由人
天命终不由人 2021-01-29 13:04

I\'m using rxjs 5.5.6.

I\'ve created this code in order to show the behavior:

Observable.of(1, 2)
    .do(a => {
        console.log(a);
        let d         


        
2条回答
  •  梦如初夏
    2021-01-29 13:33

    You get the output

    1 
    error catched
    

    because the first value throws an error in tap which is propagated through the onError channel which halts the sequence. With catch you catch this error and move on to the next sequence (never), but the first sequence (of(1,2)) is still halted. So after 1 throws an error 2 is never processed by tap.

    After you return never in catch no value is emitted and the Observable never completes. If you add logs inside subscribe for the next, error and complete callbacks you will see that they are never executed.

提交回复
热议问题