https://kotlinlang.org logo
#coroutines
Title
# coroutines
j

Joost de Vries

05/17/2019, 9:17 AM
Hi, I'm coming to coroutines from RxJs. And I'm looking for the equivalent of
switchMap
where showing search results while the user is typing. And I want to cancel all the previous requests to the server, just have the last one. In RxJs you use
switchMap
for that. What's the coroutine equivalent?
p

pawegio

05/17/2019, 9:30 AM
to
concatMap
you can:
Copy code
while(true) {
   userTypes.awaitFirst() //suspend fun
   showResult()
}
but
switchMap
might require launching coroutine in parallel and keeping reference to job to cancel it.
j

Joost de Vries

05/17/2019, 9:40 AM
I think
concatMap
would wait for the previous result. But I don't want to do that: if there's a new event I want to cancel processing of the previous.
It should be in 1.2.1
👍 2
j

Joost de Vries

05/17/2019, 9:44 AM
I didn't see it. I guess I overlooked something. Let me check.
I found it. Tx Simon!
s

simon.vergauwen

05/17/2019, 11:32 AM
Happy to help 🙂
5 Views