Last active
May 3, 2016 13:19
-
-
Save rakesh1988/f92a8fada282779f971e329e00323a76 to your computer and use it in GitHub Desktop.
debouncing retroit call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//i declare the subject globally | |
PublishSubject<Call<List<Response>>> subject = PublishSubject.create(); | |
//this is how i call retrofit | |
private void updateMarkers(LatLng center) | |
{ | |
subject.onNext(new APIHelper(). | |
GetNearByLocations("auth_key", center.latitude, center.longitude, urgency)); | |
subject.debounce(1, TimeUnit.SECONDS) | |
.observeOn(AndroidSchedulers.mainThread()) | |
.subscribeOn(Schedulers.io()) | |
.subscribe(call -> { | |
call.enqueue(new Callback<List<Response>>()// should be changed to call.clone().enqueue to avoid error | |
{ | |
@Override | |
public void onResponse(Call<List<Response>> call, Response<List<Response>> response) | |
{ | |
if (response.code() != 200) | |
{ | |
Timber.d(errorResponse.getMessage()); | |
} | |
else | |
{ | |
Timber.d("BRAVO!!!"); | |
} | |
} | |
@Override | |
public void onFailure(Call<List<Response>> call, Throwable t) | |
{ | |
Timber.d("something went wrong really bad"); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment