Skip to content

Instantly share code, notes, and snippets.

@Krishan14sharma
Created November 26, 2014 12:22
Show Gist options
  • Save Krishan14sharma/6a116632a6cd2bbf55cd to your computer and use it in GitHub Desktop.
Save Krishan14sharma/6a116632a6cd2bbf55cd to your computer and use it in GitHub Desktop.
Helper class for retrofit callback
package krishan.dhancha.api.helper;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class CancelableCallback<T> implements Callback<T> {
private final Callback callback;
private boolean canceled;
public CancelableCallback(Callback callback) {
this.callback = callback;
canceled = false;
}
public void cancel() {
canceled = true;
}
@Override
public void success(T t, Response response) {
if (!canceled) {
callback.success(t, response);
}
}
@Override
public void failure(RetrofitError retrofitError)
{ if (!canceled) {
callback.failure(retrofitError);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment