Basically I want to have the option of converting an Observable from flatMap to use as Completable. I am using RxJava 1.2.1 and trying to migrate to RxJava 2. Following the lead by Jake, I am removing all the Observable
public Observable<Void> saveReminder(final Reminder reminder)
{
return Observable.fromEmitter((Emitter<DataSnapshot> dataSnapshotAsyncEmitter) ->
{
FirebaseApi.getReminderReference().addListenerForSingleValueEvent(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot)
{
dataSnapshotAsyncEmitter.onNext(dataSnapshot);
dataSnapshotAsyncEmitter.onCompleted();
}
@Override
public void onCancelled(DatabaseError databaseError)
{
if (databaseError != null)
{
dataSnapshotAsyncEmitter.onError(databaseError.toException());
}
}
});
}, Emitter.BackpressureMode.LATEST).observeOn(Schedulers.io()).flatMap(reminderCardsSnapshot ->
{
try
{
return Observable.just(saveData(reminder, reminderCardsSnapshot));
} catch (Exception e)
{
return Observable.error(e);
}
});
}
I need to replace Observable
Which one?
@akarnokd I want to replace Observable
try
{
return Observable.just(saveData(reminder, reminderCardsSnapshot));
} catch (Exception e)
{
return Observable.error(e);
}
How can the above method return Completable when it is wrapped inside flatMap which returns an Observable. Can you plz change the method above to return Completable?
.flatMapCompletable(reminderCardsSnapshot ->
Completable.fromAction(() -> saveData(reminder, reminderCardsSnapshot)))
As a general tip, I suggest you walk through each method in the classes so you can build a mental map on what's available.
Agreed. But flatMapCompletable is available in RxJava2...do you know any way where we can achieve the same in RxJava 1.2.1?
Upgrade to 1.2.9.
@akarnokd Thanks 馃憤
Most helpful comment
As a general tip, I suggest you walk through each method in the classes so you can build a mental map on what's available.