Skip to content

Commit

Permalink
Cancel okhttp3 requests
Browse files Browse the repository at this point in the history
  • Loading branch information
sjudd committed Jan 24, 2016
1 parent 2e8331c commit 91c75ee
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class OkHttpStreamFetcher implements DataFetcher<InputStream> {
private final GlideUrl url;
private InputStream stream;
private ResponseBody responseBody;
private volatile Call call;

public OkHttpStreamFetcher(Call.Factory client, GlideUrl url) {
this.client = client;
Expand All @@ -40,7 +41,8 @@ public void loadData(Priority priority, final DataCallback<? super InputStream>
}
Request request = requestBuilder.build();

client.newCall(request).enqueue(new okhttp3.Callback() {
call = client.newCall(request);
call.enqueue(new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException e) {
if (Log.isLoggable(TAG, Log.DEBUG)) {
Expand Down Expand Up @@ -79,7 +81,10 @@ public void cleanup() {

@Override
public void cancel() {
// TODO: call cancel on the client when this method is called on a background thread. See #257
Call local = call;
if (local != null) {
local.cancel();
}
}

@Override
Expand Down

0 comments on commit 91c75ee

Please sign in to comment.