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

Jan

01/24/2020, 12:06 PM
hi i try to learn more about coroutine flows and i try to emulate the equivalent of rx throttleLatest i get confused about switching context for producer and consumer coroutines channels. can someone point me into a direction where to look for it? most flow/channel tutorials don't take callbacks into considerations that are not a suspend function, e.g. i can't call emit() in a callback for some reason
l

louiscad

01/24/2020, 1:18 PM
You're probably looking for
callbackFlow
or
channelFlow
. Beware that
offer
can throw when the flow collection is cancelled.
👍 1
z

Zach Klippenstein (he/him) [MOD]

01/24/2020, 2:22 PM
In particular, you can use the
buffer
and
conflate
operators immediately after those two builders to configure the buffer size of the channel they use.
👍 1
4 Views