Hi! Suppose we have class
class Test {
val data: SomeData = SomeData("1", 1)
fun foo() {
saveToDb(data)
}
private fun saveToDb(arg: SomeData) = background {
println("Doing db stuff with $arg")
}
}
In this case, field data is frozen and the class object itself - not.
But if we would move background {} directly to foo() - both data and the class object will be frozen.
class Test{
val data: SomeData = SomeData("1", 1)
fun foo() {
background {
saveToDb(data)
}
}
private fun saveToDb(arg: SomeData) {
println("Doing db stuff with $arg")
}
}
Background function:
fun background(block: () -> Unit) {
worker.execute(TransferMode.SAFE, { block.freeze() }) {
it()
}
}
Question: Why in the first case the class object is not frozen?