title: How to implement long pooling stream using rxjs?
body: <ol>
  <li>I call <code>angularService.method1</code> for id, that I need for next request</li>
  <li><p>I'd like to call <code>angularService.method2(id)</code> every second until I get the response <code>{success: true}</code> or:</p>
  
  <pre><code>{success: false, errors: [{errorCode: 'code', errorMessage: 'some error message'}]
  </code></pre></li>
  </ol>
  
  <p>After hours of trying I came to this version, and actually it works. But I have some questions</p>
  
  <ol>
  <li>Will the inner Observables be destroyed when main stream reaches "complete"?</li>
  <li><p>Is it a proper implementation or maybe I have some issues here?</p>
  
  <pre><code>this.angularService
  .method1(data)
  .flatMap((res) =&gt; {
      return Observable
          .interval(1000)
          .flatMap(() =&gt; this.angularService.method2(res.id))
          .concatMap(resp =&gt; {
              return (resp.success) ? Observable.of(resp, null) : Observable.of(resp);
          })
          .takeWhile(resp =&gt; resp);
  })
  .switchMap((res) =&gt; {
      return (!res.success &amp;&amp; res.errors) ? Observable.throw(res.errors) : Observable.of(res);
  })
  .subscribe(
      (next) =&gt; console.log(next),
      (err) =&gt; console.log(err),
      () =&gt; console.log('finished')
  );
  </code></pre></li>
  </ol>