[Fixed] How does nested RxJs retry operators work?


I’m using RxJs 5 lettable operators in Angular 5.
Based on this code sample, how will the retry work? will the error propagate to the first retry and then if it fails it will propagate to the second?

First observable:

first() {
  return Observable.create(observer => {
     observer.error('Something went wrong!')})

Second observable subscribe method call:


Thank you!


The resulting stream effectively looks like this:

Observable.create(...).pipe(retry(3), retry(1));

So the subscribe will perform first subscription, then retry(3) will perform 3 subscriptions to the source observable and after that will propagate the error to the next retry(1), which in turn will run the preceding sequence Observable.create(...).pipe(retry(3)) again so if you put console.log('subscribed') into producer function you’ll have 8 log entries.

You can learn more about the retry operator and its variations here.

Leave a Reply

(*) Required, Your email will not be published