LeoColman
03/11/2019, 2:23 AMfun bar(fn: suspend () -> Unit ) { }
fun far() {
val fn = {} // () -> Unit
bar(fn)
}
While I can easily do:
fun far() {
val fn = {}
bar { fn() }
}
serebit
03/11/2019, 2:26 AMsuspend {}
is not the same as the signature of a regular {}
.LeoColman
03/11/2019, 2:26 AMbar
I would do something with fn
that required the suspension?LeoColman
03/11/2019, 2:27 AMserebit
03/11/2019, 2:33 AMContinuation
parameterserebit
03/11/2019, 2:34 AMsuspend {}
, it’ll workserebit
03/11/2019, 2:38 AMclass Foo {
suspend fun suspended() {
println("h")
}
fun blocking() {
println("z")
}
}
/**
* We declare a package-level function main which returns Unit and takes
* an Array of strings as a parameter. Note that semicolons are optional.
*/
fun main(args: Array<String>) {
val parameters = Foo::class.java
.declaredMethods
.associate { it.name to it.parameters.map { it.type.name } }
.toMap()
println(parameters)
}
serebit
03/11/2019, 2:39 AM{blocking=[], suspended=[kotlin.coroutines.Continuation]}
LeoColman
03/11/2019, 2:46 AM