Reputation: 2053
Debouncing the search input values, I want to use switchMap()
with method which returns Flowable<List<T>>
I have edited my code using what @Maxim Ostrovidov suggest, now with debounce
I added the 3 lines, as want to go over list convert to other time and receive list, but doesn't work. I used these 3 lines in other case it works, but not with debounce
and switchMap
.flatMapIterable(items -> items)
.map(Product::fromApi)
.toList()
subscription = RxTextView.textChangeEvents(searchInput)
.toFlowable(BackpressureStrategy.BUFFER)
.debounce(400, TimeUnit.MILLISECONDS)
.observeOn(Schedulers.computation())
.switchMap(event -> getItems(searchInput.getText().toString()))
.flatMapIterable(items -> items)
.map(Product::fromApi)
.toList()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(/../);
Upvotes: 2
Views: 1013
Reputation: 11058
Because there is no Observable.switchMapFlowable
operator yet, you have to manually convert your stream using toObservable
or toFlowable
(depends on what type of stream you are planning to get eventually):
// Observable stream
RxTextView.textChangeEvents(searchInput)
.debounce(300, TimeUnit.MICROSECONDS)
.switchMap(event -> yourFlowable(event).toObservable())
...
// Flowable stream
RxTextView.textChangeEvents(searchInput)
.toFlowable(BackpressureStrategy.BUFFER) //or any other strategy
.debounce(300, TimeUnit.MICROSECONDS)
.switchMap(event -> yourFlowable(event))
...
Upvotes: 2