title: How to avoid "InternalError: too much recursion" in Angular observable?
body: <p>I've got a simple Angular observable that should run continuously, checking a time difference on each loop, and looping once a second. I'm getting "InternalError: too much recursion" when I run it. According to this: <a href="http://bonsaiden.github.io/JavaScript-Garden/#dealing-with-possible-blocking-code" rel="nofollow noreferrer">http://bonsaiden.github.io/JavaScript-Garden/#dealing-with-possible-blocking-code</a> 
  I'm using the correct method. How to fix?</p>
  
  <p>The Angular observable:</p>
  
  <pre><code>export class MyService {
    private lastHeartBeatTime = null; // Time of the last heartbeat
    private heartBeatTimeoutId = null;
  
    private secondsToHeartbeatAlert = 5; // Number of seconds of no heartbeat 
  
    constructor() {
      this.lastHeartBeatTime = performance.now(); // Initialise local heartbeat variable with current time
    }
  
    subscribeToHeartbeat(callbackfn): any {
      // Post a value via the observable to cause an alert to be raised:
      if((performance.now() - this.lastHeartBeatTime) / 1000 &gt;= this.secondsToHeartbeatAlert) return(true);
      // Create a new timeout to call this function again after the specified num of milliseconds (e.g. after 1 second):
  
      // **** PROBLEM HERE: ***
      else this.heartBeatTimeoutId = setTimeout(this.subscribeToHeartbeat(callbackfn), 1000);
    }
  }
  </code></pre>
  
  <p>Subscription within another component:</p>
  
  <pre><code>// Subscribe to heartbeat over websockets:
  MyService.subscribeToHeartbeat(this.handleHeartbeatFailure);
  
  // Handler:
    handleHeartbeatFailure:any = (message) =&gt; {
     alert('Websocket is down!")
    }
  </code></pre>