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

svenjacobs

08/30/2018, 1:33 PM
Hi all, what's the best approach for a long-running coroutine with multiple "receivers" ... let's say I have a coroutine which calculates some complex value or fetches something via network. I have multiple locations that might call this coroutine. But instead of starting this coroutine n times it should only run once an deliver the value to all receivers. Is a ConflatedBroadcastChannel here the best architectural choice? So putting the value into the channel so that everyone can take it when needed?
v

Vsevolod Tolstopyatov [JB]

08/30/2018, 2:25 PM
try
broadcast
builder, it’s builtin coroutine + channel
b

bj0

08/30/2018, 3:55 PM
if you only have a single value, you could use a
CompletableDeferred
s

svenjacobs

08/31/2018, 10:29 AM
Thank you guys. The value might be updated multiple times so I will have a look at
broadcast
. However I will keep
CompletableDeferred
in mind for possible future needs 🙂
3 Views