title: Queuing tasks with RxJava in Android
body: <p>I'm developing application for Android with background data synchronization.
  I'm currently using RxJava to post some data on server in regular intervals.
  Other than that, I'd like to provide user with a button "force sync" which will trigger sync immediately.
  I know how to use <code>Observable.interval()</code> to push data in regular time intervals and I would know how to use <code>Observalbe.just()</code> to push that one which is forced, but I'd like to queue them up if so happens that one is triggered while the previous still runs.</p>
  
  <p>So let's take example when 1min is interval of automatic sync, and let's say that sync lasts 40sec (I'm over exaggerating here just to make easier point). Now if by any chance, user presses the "force" button when the automatic is still running (or vice versa - the automatic triggers when the forced one is still running), I'd like to queue the second sync request to go just as the first one finishes.</p>
  
  <p>I've draw this image which may put some more perspective to it:</p>
  
  <p><a href="https://i.stack.imgur.com/d3Cdl.png" rel="noreferrer"><img src="https://i.stack.imgur.com/d3Cdl.png" alt="enter image description here"></a></p>
  
  <p>As you can see, the automatic is triggered (by some <code>Observable.interval()</code>), and in the middle of syncing, user presses "force" button. Now we want to wait for the first request to finish and then start again for the forced request.
  At one point, while the forced request was running, the new automatic request was triggered again which just added it to queue. After the last one was finished from the queue everything stops, and then the automatic was scheduled again little later on.</p>
  
  <p>Hope somebody can point me to correct operator how to do this. I've tried with <code>Observable.combineLatest()</code>, but the queue list was dispatched at beginning and when I added new sync to queue it did not continue when the previous operation was completed.</p>
  
  <p>Any help is greatly appreciated,
  Darko</p>