title: How to process all events of Observable in one thread, but get the latest value available in another thread in Rxjava?
body: <p>I am using RxJava2 in Android and I have the below problem, but it's not specific to Android.</p>
  
  <p>I have a <code>PublishSubject</code> to push all my events. I call <code>publishSubject.onNext()</code> in multiple parts of my code based on different events. But I have a central place in my code where I subscribe to these events. The below is the subscription code:    </p>
  
  <pre><code>publishSubject
      .observeOn(Schedulers.computation())
      .map(
          // each computation takes about 10ms
          // Do some computation and return a `computation` object
      )
      .observerOn(AndroidSchedulers.mainThread())
      .subscribe(
          // take the `computation` object and draw on screen
          // each drawing takes about 100ms
      );
  </code></pre>
  
  <p>Now, in the above case, if I call <code>publishSubject.onNext()</code> 100 times, then <code>computation</code> will be done 100 times and drawing on screen will be done 100 times.</p>
  
  <p>The thing is I care about the 100 times computation. Every event has to be computed. But not every computed object needs to be drawn. </p>
  
  <p>When the 1st <code>computation</code> object is being drawn on screen it takes 100ms to draw in MAIN thread, but by that time 10 new <code>computation</code> objects are generated in COMPUTATION thread.  So the 2nd time I draw on the screen I don't want to draw the 2nd <code>computation</code> object, but rather the latest <code>computation</code> object available for me (probably the 11th computation object).</p>
  
  <p>In short, I am looking for a way to do all computation all the time, but draw on screen only the latest computation object available at that time.</p>