title: Angular Periodic request
body: <p>i am working with Angular5, and right now I make requests each 5 sec to check the condition of the task.
  But I want to make the condition more flexible check "if the request has status code 202 make requests if 200 stop sends requests". or mb someone has better practice to do that. </p>
  
  <pre><code>#some.component.ts
    RunAsyncUpdates() {
     this._asyncService.getAsyncDataSource(this.model.id)
     .pipe(
      map(
      (resp: any) =&gt; {
        # i realy have no idea how to do this, but i am sure code must be here
        return resp.body;
      }),
      repeatWhen(() =&gt; Observable.interval(5000)),
      retryWhen(errors =&gt; errors.delay(1000).take(3)),
      takeWhile(() =&gt; this._alive)
    )
    .subscribe(
      (data: any) =&gt; {
        if (!data) { return; }
        console.log(data);
        this._asyncService.data_stream$.next(data);
      }
    );
  
  
  
  #some.service.ts
  getAsyncDataSource(item): Observable&lt;HttpResponse&lt;any&gt;&gt; {
  const uri = `${this.base_service.getBaseUrl()}/async/${item}/`;
  return this.httpClient.get&lt;any&gt;(uri, {observe: 'response'});
  </code></pre>
  
  <p><strong>EDIT:</strong> this works very well </p>
  
  <pre><code>this.route.parent.params.pipe(
    switchMap((params: Params) =&gt; this._asyncService.loadAsyncData(params['id'])
  // get parametr from route
      .pipe(
        map((resp: any) =&gt; {
            if (resp.status !== 202) {
              throw resp; // This error will be picked up by retryWhen
            }
            return resp.body;
          }),
        repeatWhen(() =&gt; Observable.interval(5000)),
        retryWhen(errors =&gt; errors.delay(1000).take(3)),
        takeWhile(() =&gt; this._alive),
      )),
    takeWhile(() =&gt; this._alive),
  ).subscribe(
      (data: any) =&gt; {
        if (!data) {return; }
        this._asyncService.data_stream$.next(data);
      }
    );
  </code></pre>