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

myanmarking

01/22/2020, 4:44 PM
what is the proper way of sharing a flow ?
d

Dominaezzz

01/22/2020, 4:48 PM
m

myanmarking

01/22/2020, 4:49 PM
something like this:
Copy code
val flow = callbackFlow{
    offer(dispatchValue1())
    offer(dispatchValue2())
    offer(dispatchValue3())
    close()
}
collecting this flow multiple times will only call those functions once
d

Dominaezzz

01/22/2020, 4:51 PM
So it will call the functions once, but will it return the same items again or will it just continue onto the next function that hasn't been called?
m

myanmarking

01/22/2020, 4:53 PM
this was a silly example 😛 Let's say i have table in the database that i'm observing. then i collect that flow two times, i want them to 'share' results
as in, not being cold, and perform the work twice
d

Dominaezzz

01/22/2020, 4:57 PM
Interesting. The link I sent you one part of what you're looking for.
I'll look for the other.
m

myanmarking

01/22/2020, 4:57 PM
yes, i know 😛 but not ready yet. thanks for your help
p

Paul Woitaschek

01/22/2020, 6:23 PM
Still looking for a alternative to replay(1).refcount()
👍 1
3 Views