Skip to content

Instantly share code, notes, and snippets.

@rakesh1988
Last active May 3, 2016 13:19
Show Gist options
  • Save rakesh1988/f92a8fada282779f971e329e00323a76 to your computer and use it in GitHub Desktop.
Save rakesh1988/f92a8fada282779f971e329e00323a76 to your computer and use it in GitHub Desktop.
debouncing retroit call
//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