This library come to aid when we need to do polling requests. The library take care to do the polling when data is resolved. This strategy help us to prevent send requests before the previous request return.
project have dependencies that require rxjs 6.4.0 or higher.
npm i @rifo/rxjs-polling
import { Component } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { pollingOnResolved } from '@rifo/rxjs-polling';
@Component({
selector: 'app-root',
templateUrl: `<div>{{response$ | async}}</div>`,
styleUrls: ['./app.component.scss']
})
export class AppComponent {
response$: Observable<string>;
constructor(private http: HttpClient) {
const httpRequest$ = this.http.get(`https://blockchain.info/ticker`);
this.response$ = pollingOnResolved(httpRequest$, 2_000);
}
}