Skip to content

Commit

Permalink
Use execute() instead of enqueue() in Rx adapter
Browse files Browse the repository at this point in the history
Retrofit should leave threading up to the Scheduler used to invoke call().

Otherwise, there can be two types of unwanted behavior:

1. It can execute on another Thread when sync behavior is desired.

2. It uses unnecessary extra Threads even when already called on a Scheduler.
  • Loading branch information
dlew committed Sep 25, 2015
1 parent 5d249a3 commit 38ce2be
Showing 1 changed file with 16 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,31 +102,25 @@ private CallOnSubscribe(Call<T> originalCall) {
}
}));

call.enqueue(new Callback<T>() {
@Override public void onResponse(Response<T> response, Retrofit retrofit) {
if (subscriber.isUnsubscribed()) {
return;
}
try {
subscriber.onNext(response);
} catch (Throwable t) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(t);
}
return;
}
if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
if (subscriber.isUnsubscribed()) {
return;
}

@Override public void onFailure(Throwable t) {
if (subscriber.isUnsubscribed()) {
return;
}
try {
Response<T> response = call.execute();
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(response);
}
} catch (Throwable t) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(t);
}
});
return;
}

if (!subscriber.isUnsubscribed()) {
subscriber.onCompleted();
}
}
}

Expand Down

0 comments on commit 38ce2be

Please sign in to comment.