Rxjs Retry with Delay function

delay() is used to introduce a delay between events emitted by the observable. But the observable never emits any event. It just errors immediately. What you’re looking for is retryWhen(), which allows deciding after how long to retry: RxJS 5: .retryWhen(errors => errors.delay(1000).take(10)) RxJS 6: import { retryWhen, delay, take } from ‘rxjs/operators’ someFunction().pipe( // … Read more

Angular 2 Observable with multiple subscribers

I encountered a similar problem and solved it using Aran’s suggestion to reference Cory Rylan’s Angular 2 Observable Data Services blog post. The key for me was using BehaviorSubject. Here’s the snippets of the code that ultimately worked for me. Data Service: The data service creates an internal BehaviorSubject to cache the data once when … Read more

Upgrading to Angular 10 – Fix CommonJS or AMD dependencies can cause optimization bailouts

When you use a dependency that is packaged with CommonJS, it can result in larger slower applications Starting with version 10, Angular now warns you when your build pulls in one of these bundles. If you’ve started seeing these warnings for your dependencies, let your dependency know that you’d prefer an ECMAScript module (ESM) bundle. … Read more

Observable Finally on Subscribe

The current “pipable” variant of this operator is called finalize() (since RxJS 6). The older and now deprecated “patch” operator was called finally() (until RxJS 5.5). I think finalize() operator is actually correct. You say: do that logic only when I subscribe, and after the stream has ended which is not a problem I think. … Read more

How to make a sequence of http requests in Angular 6 using RxJS

For calls that depend on previous result you should use concatMap firstPOSTCallToAPI(‘url’, data).pipe( concatMap(result1 => secondPOSTCallToAPI(‘url’, result1)) concatMap( result2 => thirdPOSTCallToAPI(‘url’, result2)) concatMap(result3 => fourthPOSTCallToAPI(‘url’, result3)) …. ).subscribe( success => { /* display success msg */ }, errorData => { /* display error msg */ } ); if your async method does not depend on … Read more

How to make an http call every 2 minutes with RXJS?

Since you are already using Observables, simply make full use of it 🙂 Obersvable.interval() is your good friend here: In your component, do this: Observable .interval(2*60*1000) .timeInterval() .mergeMap(() => this.notificationService.getNotifications(this.token)) .subscribe(data => { console.log(data); }); Explanation: .interval() creates an observable that emits an event every 2 minutes. .timeInterval() convert an Observable that emits items into … Read more