I'm using RxJava along with AWS API Gateway in my app.
The code is here:
@Override
public Single<SearchResponse> searchPostsApiCall(String keyword, String offset) {
return Single.fromCallable(() -> client.postSearch(keyword,offset));
}
// to call api
getCompositeDisposable().add(searchPostsApiCall(keyword,offset)
.subscribeOn(getSchedulerProvider().io())
.observeOn(getSchedulerProvider().ui())
.subscribe(response -> onResponseReceived(response, offset, finalType), this::onError)
);
The issue is that when user during search changes text too frequently and api call is already in process then i want to cancel previous call before sending new hit as i don't want response of previous hit due to changed query.
I tried using disposable.cancel too but it gives error
'ApiClientException: java.io.InterruptedIOException: thread interrupted'
How can i achieve my target to save my hits? Any idea will be appreciable.
Thanks