title: How do I convert async task/ rx java code to rxjava2?
body: <p>I tried converting my <code>AsyncTask</code> code below to <code>Rxjava2</code>, but apparently <code>Rxjava2</code> doesn't deal with null values and hence my app crashes. Here's my code for <code>AsyncTask</code>: </p>
  
  <pre><code>new AsyncTask&lt;Void, Void, Void&gt;() {
              @Override
              protected Void doInBackground(Void... params) {
                  Set&lt;Map.Entry&lt;String, Participant&gt;&gt; entries = pool.entrySet();
                  for (Map.Entry&lt;String, Participant&gt; entry : entries) {
                      Participant participant = entry.getValue();
                      participant.release();
                  }
                  return null;
              }
  
              @Override
              protected void onPostExecute(Void aVoid) {
                  cb.event(new Spin.Event&lt;Void&gt;());
              }
          }.execute();
  </code></pre>
  
  <p>And here's the converted code to <code>Rxjava</code> (NOT <code>Rxjava2</code>) :</p>
  
  <pre><code> Observable.defer(new Func0&lt;Observable&lt;Void&gt;&gt;() {
          @Override
          public Observable&lt;Void&gt; call() {
              Set&lt;Map.Entry&lt;String, Participant&gt;&gt; entries = pool.entrySet();
              for (Map.Entry&lt;String, Participant&gt; entry : entries) {
                  Participant participant = entry.getValue();
                  participant.release();
              }
              return Observable.just(null);
          }
      }).doOnCompleted(new Action0() {
          @Override
          public void call() {
              cb.event(new Spin.Event&lt;Void&gt;());
          }
      })
      .subscribeOn(Schedulers.computation())
      .subscribe();
  </code></pre>
  
  <p>What would be the best approach to convert it to <code>Rxjava</code> without it crashing  on returning null. Also, how does the .execute() play with respect to <code>Rxjava2</code>? not sure if that even works in <code>Rxjava</code>?</p>
  
  <p>Here's the crash log:</p>
  
  <pre><code>FATAL EXCEPTION: RxComputationThreadPool-3
  
                                                                             io.reactivex.exceptions.OnErrorNotImplementedException: null ObservableSource supplied
                                                                                 at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:704)
                                                                                 at io.reactivex.internal.functions.Functions$OnErrorMissingConsumer.accept(Functions.java:701)
                                                                                 at io.reactivex.internal.observers.LambdaObserver.onError(LambdaObserver.java:74)
                                                                                 at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeOnObserver.onError(ObservableSubscribeOn.java:63)
                                                                                 at io.reactivex.internal.disposables.EmptyDisposable.error(EmptyDisposable.java:63)
                                                                                 at io.reactivex.internal.operators.observable.ObservableDefer.subscribeActual(ObservableDefer.java:35)
                                                                                 at io.reactivex.Observable.subscribe(Observable.java:10842)
                                                                                 at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
                                                                                 at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:38)
                                                                                 at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:26)
                                                                                 at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154)
                                                                                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                 at java.lang.Thread.run(Thread.java:818)
                                                                              Caused by: java.lang.NullPointerException: null ObservableSource supplied
                                                                                 at io.reactivex.internal.functions.ObjectHelper.requireNonNull(ObjectHelper.java:39)
                                                                                 at io.reactivex.internal.operators.observable.ObservableDefer.subscribeActual(ObservableDefer.java:32)
                                                                                 at io.reactivex.Observable.subscribe(Observable.java:10842) 
                                                                                 at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96) 
                                                                                 at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:38) 
                                                                                 at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:26) 
                                                                                 at java.util.concurrent.FutureTask.run(FutureTask.java:237) 
                                                                                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:154) 
                                                                                 at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269) 
                                                                                 at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 
                                                                                 at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 
                                                                                 at java.lang.Thread.run(Thread.java:818) 
  </code></pre>