Can we only allow the latest consumer receive data...
# announcements
s
Can we only allow the latest consumer receive data when use
flow
? For example,
Copy code
val flow = flow { 
    var i = 0
    while(true) { 
        delay(1000) 
        println("Emit $i")
        emit(i++)
    }
}
Copy code
launch { flow.collect { println("A: got $it") } }
launch { flow.collect { println("B: got $it") } }
I want only B can get data and if B stop collect than A can get data.
a
I think this is not possible out of the box currently. For this you would probably need the SharedFlow which is not implemented yet.
❤️ 1
s
Or is there similar library can implement this? RxKotlin? but I cant found which operators can do this. 😥
a
It is relatively easy to achieve with classic Rx approach. But AFAIK there is no out of the box operator for this. I could drop an example later.
s
Maybe only need the keyword. I used Rx before. Thank you.
a
So with Reaktive I would do something like this: https://pastebin.com/f0vKUueM Did not test it though. With other Rx libs should be pretty much same.
👍 1