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

voben

01/08/2020, 7:43 PM
I’m trying to communicate between an activity and a fragment using a Conflated channel. I send a value to the channel from the activity before the fragment is initialized. Once initialized, the fragment should consume the value. But I would like the channel to no longer emit a value after the fragment consumes it. How do I do this?
r

rrva

01/08/2020, 7:48 PM
use a flow instead of a channel?
v

voben

01/08/2020, 7:49 PM
I already consume the value as a flow. But send it through a channel
z

Zach Klippenstein (he/him) [MOD]

01/08/2020, 7:58 PM
Why are you using a conflated channel?
v

voben

01/08/2020, 9:18 PM
I need a way to hold onto the value before the fragment is initialized. Would you recommend a Rendevouz channel or something else instead?
z

Zach Klippenstein (he/him) [MOD]

01/08/2020, 10:55 PM
You could just give the channel a capacity of 1, then the initial send will succeed immediately, but once the value is received from the channel it won’t be received again.
v

voben

01/08/2020, 11:03 PM
You mean like so?
Copy code
val myChannel = Channel<String>(1)
z

Zach Klippenstein (he/him) [MOD]

01/08/2020, 11:15 PM
yep!
d

Dico

01/09/2020, 12:24 AM
If it's just one value I would recommend
CompletableDeferred
☝️ 1
4 Views