Johann Pardanaud
05/11/2023, 3:07 PMfun runBlock(block: () -> Unit) = block()
suspend fun runBlock(block: suspend () -> Unit) = block()
runBlock { println("hello") }
^ COMPILE ERROR: Suspend function 'runBlock' should be called only from a coroutine or another suspend function
runBlock(suspend { println("hello") })
^ COMPILE ERROR: Suspend function 'runBlock' should be called only from a coroutine or another suspend function
Or should I create two functions, runBlock
and runSuspendableBlock
?
(sorry, I post quite often lately 😓 )Sam
05/11/2023, 3:14 PMrunBlock
was inline
it would work. But in the general case, no, a suspend
function can’t overload or override a non-suspending function 😞Johann Pardanaud
05/11/2023, 3:15 PMSam
05/11/2023, 3:19 PMsuspend { println("hello") }
you are actually creating an instance; it’s no longer inlineJohann Pardanaud
05/11/2023, 3:40 PM