I am learning Kotlin coroutines. The first code example is:
fun main() = runBlocking { ... }
The signature for runBlocking is:
public actual fun <T> runBlocking(context: CoroutineContext, block: suspend CoroutineScope.() -> T): T
There is no default value specified for context. How is context supplied without me specifying it and with no default specified?
Joffrey is correct that the default value is EmptyCoroutineContext. You can see in the latest commit as of writing the default value was removed.
You can see in that commit, the function was changed to actual fun, probably in support of some multiplatform changes per the commit message. If you have an expect fun with a default argument, and you also try adding it to the actual fun you get the error
Actual function cannot have default argument values, they should be declared in the expected function
The expect fun declaration is in Builders.concurrent.kt, defined with the EmptyCoroutineContext
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With