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

Patrick Jackson

07/29/2019, 5:30 PM
Flow question: What is recommended way to get a flow of tap events. In android we give views a callback for these events. This is where many devs will try to get started with flows, yet is unclear how to do so. Is best way to use flowViaChannel with a callback that does channel.offer()? Any thoughts on this?
z

Zach Klippenstein (he/him) [MOD]

07/29/2019, 5:34 PM
Generally yes, that is how you bridge callback code to Flow code. Although note that
flowViaChannel
has been deprecated in favor of
channelFlow
.
Although if the listener you’re registering is a
setFoo
instead of
addFoo
, you might need to multicast. You could use a
BroadcastChannel
or David Karnok’s new library: https://github.com/akarnokd/kotlin-flow-extensions
2 Views