title: How to use $interval for continuous polling in Angular?
body: <p>In my Angular code, I have a code for long polling, that looks like this</p>
  
  <pre><code>var request = function() { 
      $http.post(url).then(function(res) {
          var shouldStop = handleData(res);
          if (!shouldStop()) {
              request()
          }
       };
  }
  request();
  </code></pre>
  
  <p>The function gets called immediately after the page load.</p>
  
  <p>However, now I am trying to set up testing in Protractor and I got this error message</p>
  
  <blockquote>
    <p>Failed: Timed out waiting for Protractor to synchronize with the page after 11 seconds. Please see 
    <a href="https://github.com/angular/protractor/blob/master/docs/faq.md" rel="nofollow">https://github.com/angular/protractor/blob/master/docs/faq.md</a>. The following tasks were pending:</p>
  </blockquote>
  
  <p>In the <a href="https://github.com/angular/protractor/blob/master/docs/timeouts.md" rel="nofollow">docs</a>, I read the following:</p>
  
  <blockquote>
    <p>Before performing any action, Protractor asks Angular to wait until the page is synchronized. This means that all timeouts and http requests are finished. If your application continuously polls $timeout or $http, it will never be registered as completely loaded. You should use the $interval service (interval.js) for anything that polls continuously (introduced in Angular 1.2rc3).</p>
  </blockquote>
  
  <p>How should I edit my code to use <code>$interval</code>? I thought that interval is an angular wrapper for <code>window.setInterval</code>, I am not sure how to use that for long polling.</p>