title: Using Observable.interval() to advance time for "time blocks" stored in an array
body: <p>New to RxJava - looking for some feedback.</p>
  
  <p>Scenario: I have a list of time blocks of various lengths (i.e one is 5 minutes long, another 30 seconds, etc). I use Observable.from to create an observable: <code>timeline = Observable.from(timeBlocks);</code> What I'd like to do is mix this with an interval observer, <code>Observable&lt;Long&gt; intervalObs = Observable.interval(1000, TimeUnit.MILLISECONDS);</code> to progress through time for each time block in sequence. So if the first time block's duration is 5 minutes and 5 minutes have passed then move on to the next time block in sequence. </p>
  
  <p>Some other details: </p>
  
  <ul>
  <li>the list can change (I'm not even sure the best way to deal with that using rx) so block can be added/removed/have their duration changes/re-ordered. </li>
  <li>timer needs to be able to pause/stop</li>
  <li>Other components will also need to tap into this stream (to update UI for example)</li>
  </ul>
  
  <p>Right now this is what I have after trying several approaches that seems to work but also seems inefficient and just looks wrong (I subscribe when time starts and unsubscribe when pausing/stopping):</p>
  
  <pre><code>intervalObs 
   .subscribe(new Subscriber() {
                  @Override
                  public void onCompleted() {
                  }
  
                  @Override
                  public void onError(Throwable e) {
  
                  }
  
                  @Override
                  public void onNext(Object o) {
                      timeline.first(new Func1&lt;TimeBlock, Boolean&gt;() {
                          @Override
                          public Boolean call(TimeBlock timeBlock) {
                              return timeBlock.getTimeLeft() &gt; 0;
                          }
                      }).subscribe(new Action1&lt;TimeBlock&gt;() {
                          @Override
                          public void call(TimeBlock timeBlock) {
                              timeBlock.addTime(1000);
                          }
                      });
                  }
              });
  </code></pre>
  
  <p>What's a better way to do this? Should I structure things differently/conceptualize it in a different way?</p>
  
  <p>Let me try to clear up the use case: </p>
  
  <p>An app that lets you create lists of tasks and assign a duration to them. You can then import any subset of those tasks into a timer. The timer just increments the time spent on each task starting with the top one first. When the task's duration is reached, you move on to the next task. You should be able to pause/resume/re-arrange the order of the tasks/edit the tasks/etc and the timer adjusts. </p>
  
  <p>You can also pre-select a cycle pattern - i.e say you want to work in blocks of 25 minutes. The timer will create however many time blocks of 25 minutes needed to complete all the tasks based on their total duration. The timer then does the same thing as described above, increasing the time spent on each time block (and the time spent on the tasks contained with in it) until duration is reached then moves on to the next.</p>