title: How to stop emission from PublishSubject when buffer is empty
body: <p>I'm trying to create a sequential download service using RxJava.
  User can add items in batch (20, 30 etc) or individual item. These items will be added to queue and then, downloaded sequentially in batches of 10.
  For that I am using PublishSubject:</p>
  
  <pre><code>PublishSubject&lt;Int&gt; pubSubject = PublishSubject.create();
  </code></pre>
  
  <p>which emits item (ids) added by user, and then apply buffer operator to batch items. Using these ids, items are downloaded in flatMap and return in onNext of subscription.</p>
  
  <pre><code>  pubSubject.buffer(1, TimeUnit.SECONDS, 10)
              .observeOn(Schedulers.io())
              .flatMap { idsBatch -&gt; downloadByIds(idsBatch) }
              .subscribe(
                  /* onNext */ { apiResponse -&gt; handleResponse() },
                  /* onError */ { handleError(it) },
                  /* onComplete*/ { hideProgressBar() }
               )
  </code></pre>
  
  <p>Code is mostly working as expected. Items are batched and downloaded successfully but even after all items are emitted, buffer still calls flatMap with empty list and onComplete() is never called.</p>
  
  <p>I want  to know if there is any method or way in RxJava to get onComplete callback when there are no more items in buffer. Because else my download service never terminates.</p>