Why are my interval polling requests occurring only once?

霸气de小男生 提交于 2019-12-24 06:42:00

问题


I am trying to make a simple polling service using rxjs and angular 7 and am running into a recurring issue that my requests are only actually being fired once but the interval completes successfully with no errors.

My service component looks like this:

    import { HttpClient, HttpHeaders, HttpRequest } from '@angular/common/http';
    import { interval, Subject } from 'rxjs/index';
    import { exhaustMap } from 'rxjs/internal/operators';

      constructor( private httpClient: HttpClient ) {
      }

     getPing() {
        const req = new HttpRequest('GET', this.getUrl, {responseType: 'blob', headers: new HttpHeaders(), reportProgress: true});
            interval(1000)
              .pipe(take(4))
              .pipe(exhaustMap(()=> this.httpClient.request(req)))
              .subscribe(data => console.log(data));
     }

I have console logs showing that the interval occurs and completes after 4 intervals but only the first request is called according to the network tab.
If I use fetch instead of http client or change the interval to a loop the service behaves as expected however I would prefer to not use those approaches. Does anybody know what I'm missing?

I am using angular 7.0.0 and rxjs 6.2.2 Console logs Network Tab

来源:https://stackoverflow.com/questions/54369125/why-are-my-interval-polling-requests-occurring-only-once

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!