I created an Observable that emits text from edittext. Then in using the switchmap operator, I create a Single that looks for a match in the file.
Here I subscribe:
compositeDisposable.add(getEditTextObservable(editText)
.debounce(500, TimeUnit.MILLISECONDS)
.map(String::toLowerCase)
.filter(s -> !TextUtils.isEmpty(s))
.switchMapSingle(s -> textCutter.getSearchResult(s))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe()
);
Here is the search:
public Single<List<TextCut>> getSearchResult(String searchRequest) {
return Single.fromCallable(() -> textGen.getCutList(searchRequest));
}
As a result, I get that each request is executed in turn. For example, if I enter the query "dog", and then "cat", as a result I get both "dog" and "cat". Although I expected to get only the "cat"
For example:
input: dog
"dog" in progress...
input: cat
output: [result of 'dog']
"cat" in progess...
output: [result of 'cat']
What I expected to get:
input: dog
"dog" in progress...
input: cat
"dog" canceled...
"cat" in progess...
output: [result of 'cat']