ursus
10/24/2020, 3:40 AMgildor
10/24/2020, 6:12 AMursus
10/24/2020, 1:00 PMgildor
10/24/2020, 1:46 PMursus
10/24/2020, 1:50 PMgildor
10/24/2020, 1:55 PMursus
10/24/2020, 2:27 PMgildor
10/25/2020, 12:18 PMpeople can forget and just use blocking but you can also do this with coroutinesBut you cannot prevent it, I just cannot imagine solution for this you want to prevent calling any other methods? it’s not how suspend functions work, they do not prevent calling any other functions, coroutines just require context, it’s the same as TScope, but it implicit (same for @Compose functions), so you cannot call suspend function out of this context, but do not prevent calling any other functions Compose is good example, to call suspend composable functions, you need both and suspend modifier and @Compose annotation to work, they do not restrict anything Of course it can be some language feature/plugin, which prevents calling any other functions, but it would be incredible unusable:
transaction {
startTransaction ()
log("starting") // error! Not a transaction function
val result = doSomething(
getSomeData() // error!
.trim() // error!
)
result.forEach { // error!
val item = it
.toString() // error!
.trim() // error!
doSomethingNonTransactional(item) // error
}
}
And to cover all those cases you essentially need whole new language just to make it work, which doesn’t really make sense for me, and after all this cannot prevent all cases of “blockling functions”, forEach is blocking function, depends on amount of data