I recently started learning RxJava and applied it to a small part of my project. It turns out that this part is small, but one with "high traffic": it is often called other components. An example is a network client that is called repeatedly to retrieve remote data, applies several transformations to the response, and then fires a callback event. Let's say these conversions are easy, so I can do this in the main thread:
restService.getData()
.observeOn(AndroidSchedulers.mainThread())
.map(data -> someMapping(data))
.map(data -> someOtherMapping(data))
.subscribe(this::fireResponseCallback, this::fireErrorCallback)
Now the same thing can be done without RxJava:
restService.getData()
.enqueue(new Callback<T>() {
@Override
public void onResponse(Call<T> call, Response<T> response) {
T data = response.body();
data = someMapping(data);
data = someOtherMapping(data);
fireResponseCallback(data);
}
@Override
public void onFailure(Call<T> call, Throwable t) {
fireErrorCallback(t);
}
});
, RxJava, , . 4 -, 1 (Func1<> Action1<>). RxJava 1 (Callback<T>). , . , , RxJava? , ?