title: Reset the Observable Timer on user action?
body: <p>In my angular project, I need to refresh the token before it expires by doing user interaction. on UI we display session timeout message and a renew icon just before 5 minutes before it expires and when user click on renew icon we refresh the token and now it again checks the session with this new token and so on.</p>
  
  <ul>
  <li><p>RxJs v 5.1</p></li>
  <li><p>Angular v 4.0</p></li>
  </ul>
  
  <p>I was using <code>setInterval()</code> and <code>clearInterval()</code>   and here is relevant code</p>
  
  <pre><code>@Compononet({})
  export class AdminLayoutComponent implements OnInit {
      isRefreshingToken: boolean;
      interval: any;
      period: number;
      constructor() {
          this.notifyMinutes = 5; // in minutes
          this.isRefreshingToken = false;
          this.period = 60 * 1000;
          this.timer$ = Observable.timer(0, this.period);
      }
  
      ngOninit() {
          this.interval = &lt;any&gt;setInterval(() =&gt; this.checkSession(), this.period);
      }
  
      private checkSession() {
          // calculate the remaining time and display the message accordingly
          if (remainingTime &lt; 5 minutes) {
              this.refreshTokenMethod.finally(() =&gt; {
                  this.isRefreshingToken = false;
              }).subscribe() {
                  this.isRefreshingToken = true;
              }
          }
      }
      ngOnDestroy() {
          if (this.interval) {
              clearInterval(this.interval);
          }
  
      }
  }
  </code></pre>
  
  <p>This is working fine but I think Observables are a better tool to achieve the same. so tried this way</p>
  
  <pre><code>export class AdminLayoutComponent implements OnInit {
  
      timer$: Observable&lt;any&gt;;
      subscription: Subscription;
  
      constructor() {
          this.timer$ = Observable.timer(0, this.period);
      }
  
      ngOnInit() {
          this.subscription = this.timer$.subscribe((i) =&gt; {
              console.log('timer: ', i);
              this.checkSession();
          });
      }
  
      ngOnDestroy() {
          if (this.subscription) {
              this.subscription.unsubscribe();
          }
      }
  }
  </code></pre>
  
  <p>Now problem is that when the user clicks on renew icon; I want to reset the timer again to check the timing.</p>
  
  <p>How can I do this? or is it okay to run timer?</p>