I've done an Rxjava wrrapper for firebase signInWithCustomToken()
method, here is the code:
public Observable<AuthResult> signInWithCustomToken(String token) {
return Observable.create(new ObservableOnSubscribe<AuthResult>() {
@Override public void subscribe(ObservableEmitter<AuthResult> emitter) throws Exception {
firebaseAuth.signInWithCustomToken(token)
.addOnSuccessListener(new OnSuccessListener<AuthResult>() {
@Override public void onSuccess(AuthResult result) {
emitter.onNext(result);
}
})
.addOnFailureListener(new OnFailureListener() {
@Override public void onFailure(@NonNull Exception e) {
emitter.onError(e);
}
})
.addOnCompleteListener(new OnCompleteListener<AuthResult>() {
@Override public void onComplete(@NonNull Task<AuthResult> task) {
emitter.onComplete();
}
});
}
});
}
so I was wondering what is the lifecycle of the three listeners (OnSuccessListener
- OnFailureListener()
- OnCompleteListener
) inside the Rx callback, Do they have the same lifecycle of the return Observable, in other words if I called observable.dispose()
, will they be cleared from memory?
and I have another question sorry, is this the best way for modeling such a method in Rx way?
thank you in avance.