altavir
08/12/2022, 10:37 AMPetter Måhlén
08/12/2022, 11:47 AMDisposable
that handles unsubscribing. So
fun MyStructure.onChange(block: MyStructure.(Key) -> Unit): Disposable
val disposable = myStructure.onChange { key ->
println(get(key))
}
disposable.close()
That brings it closer to the Flow version, makes it more convenient/somewhat less likely that you’ll forget unsubscribing, and makes the key used to track subscription identity an internal detail of MyStructure
.altavir
08/12/2022, 11:52 AMFlow
variant is that in general you do not have to bother since the lifecycle is handled by the CoroutineScope.Petter Måhlén
08/12/2022, 3:15 PMaltavir
08/12/2022, 3:19 PM