title: How to unsubscribe or dispose an interval observable on condition in Angular2 or RxJS?
body: <p>I'm new to the whole Rx thing and reactive programming, however I have to deal with such a situation. I want a interval observable to check a hardware's status by a POST request to its REST API every 500ms to see if the response changes. So once it changes, I want such interval observable POST request shut down immediately, leaving resource to other future operations. Here is a piece of code.</p>
  
  <pre><code>myLoop(item_array:number[], otheroption : string){
      for (let item of item_array){
          //set hardware option, still a request
          this.configHardware(item,otheroption)
          //after config the hardware, command hardware take action
              .flatMap(() =&gt; {
                  //this return a session id for check status
                  this.takeHardwareAction()
                      .flatMap( (result_id) =&gt; {
                          //I want every 500ms check if hardware action is done or not
                          let actionCheckSubscription = IntervalObservable.create(500).subscribe(
                              () =&gt; {
                                  //So my question is, can I unsubscribe the actionCheckSubscription in here on condition change? For example, 
                                  if (this.intervalCheckingStatus(result_id))
                                      actionCheckSubscription.unsubscribe() ;
                              }
                          ) ;
                      })
  
              })
      }
  }
  </code></pre>