Moya: 11.0.2
I use RxMoya for a search, I start a request as the user types, how could I cancel the previous requests?
You can use flatMapLatest: flatMapLatest only emits elements from the most recent inner Observable sequence.
self.searchController.searchBar.rx.text
.orEmpty
.debounce(0.5, scheduler: MainScheduler.instance)
.distinctUntilChanged()
.filter { !$0.isEmpty && $0.count > 2 }
.flatMapLatest { (query) -> Observable<String> in
return network.searchUser(matching: query)
}
.subscribe(onNext: { users in
self.users = users
//update view
}).disposed(by: self.disposeBag)
This issue has been marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
This issue has been auto-closed because there hasn't been any activity for at least 21 days. However, we really appreciate your contribution, so thank you for that! 馃檹 Also, feel free to open a new issue if you still experience this problem 馃憤.
Most helpful comment
You can use flatMapLatest: flatMapLatest only emits elements from the most recent inner Observable sequence.