title: Wrapping a Firebase Task<Void> into RxJava CompletableEmitter?
body: <p>I am trying to wrap a <strong>Firestore method</strong> into CompletableEmitter, to be able to return Completable.complete() on success/complete, and Completable.error() on failure.
  (The Task is a Firestore operation to update a document(1 field in that document) in a collection)</p>
  
  <p><a href="https://firebase.google.com/docs/reference/android/com/google/firebase/firestore/DocumentReference.html#update(java.util.Map%3Cjava.lang.String,%20java.lang.Object%3E)" rel="nofollow noreferrer">This</a> is the <code>firestore method</code> I am trying to wrap into a <a href="http://reactivex.io/RxJava/javadoc/io/reactivex/Completable.html" rel="nofollow noreferrer">Completable</a> which returns a <code>Task&lt;Void&gt;</code>. And here is the code without having it wrapped in a Completable:</p>
  
  <pre><code>public static Completable updateDocument(DocumentReference ref, Map&lt;String,Object&gt; fieldsAndValues){
      ref.update(fieldsAndValues)
                  .addOnSuccessListener(aVoid -&gt; {
                      Timber.d("SUCCESS");
                  }).addOnCompleteListener(task -&gt; {
                      Timber.d("COMPLETE");
                  }).addOnFailureListener(e -&gt; {
                      Timber.d("ERROR");
                  });
          return Completable.complete();    //just for the sake of returning complete to finish the method...
  }
  </code></pre>
  
  <p>This above code executes as is should.</p>
  
  <p>Here is my attempt to wrap that code :</p>
  
  <pre><code>public static Completable updateDocument(DocumentReference ref, Map&lt;String,Object&gt; fieldsAndValues){
      return Completable.create(emitter -&gt; ref.update(fieldsAndValues)
         .addOnSuccessListener(aVoid -&gt; emitter.onComplete())
         .addOnCompleteListener(task -&gt; emitter.onComplete())
         .addOnFailureListener(emitter::onError));
  }
  </code></pre>
  
  <p>While the first executes with success (onSuccess called, document in Firestore updated), the wrapped code never reaches onSuccess from the Task (onSuccess never reached, document never updated in Firestore). But it does not throw any errors, The Task completes but never reaches success.</p>
  
  <p>I do not understand this behavior. Any suggestions? What do I do wrong here?</p>