https://kotlinlang.org logo
#flow
Title
d

dead.fish

01/05/2022, 3:11 PM
Hi all! Is there a better / more idiomatic way to do this? I.e. provide values to a flow lazily that is not owned by the producer? I fail to see how I could else use a cold
flow {}
in this example, while being able to share emissions from it with `someExternalFlow`:
Copy code
val someExternalFlow: MutableSharedFlow<ProcessedData>()
fun updateData(data: Data) {
  if (someExternalFlow.subscriptionCount.value > 0) {
    someExternalFlow.tryEmit(computeExpensively(data))
  }
}