Animesh Sahu
02/14/2021, 5:58 AMfun test(a: () -> Unit) { println("A") }
fun test(a: suspend () -> Unit) { println("B") }
suspend fun main() {
test {}
}
According to the language i.e. if kotlin - allow suspend lambda whereas call from non-kotlin like java/js - allow normal lambda 👀Animesh Sahu
02/14/2021, 6:05 AMtest(suspend {
...
})
And the first function (takes nothing) should be able to be called from Java/JS (without continuation parameter).
My next question, is there a way to distinguish them without suspend
function call on the stdlib? Like being able to put the trailing lambda outside parenthesis?Animesh Sahu
02/14/2021, 6:08 AMsuspend
(in trailing lambda manner) so neither first nor second can be called without explicitly calling suspend()
and qualifying the lambda explicitly suspensive.Youssef Shoaib [MOD]
02/14/2021, 2:03 PMinline fun test(a : () -> Unit)
and if it's called in a suspending context in Kotlin then you'll be able to call suspend functions in there too.Animesh Sahu
02/14/2021, 3:19 PMAnimesh Sahu
02/14/2021, 3:20 PMYoussef Shoaib [MOD]
02/14/2021, 3:22 PMYoussef Shoaib [MOD]
02/14/2021, 3:23 PM@JvmName("test")
fun testJvm(a: () -> Unit) { println("A") }
fun test(a: suspend () -> Unit) { println("B") }
suspend fun main() {
test {}
}
Animesh Sahu
02/14/2021, 3:23 PMYoussef Shoaib [MOD]
02/14/2021, 3:23 PMYoussef Shoaib [MOD]
02/14/2021, 3:24 PMAnimesh Sahu
02/14/2021, 3:24 PMAnimesh Sahu
02/14/2021, 3:24 PMAnimesh Sahu
02/14/2021, 3:24 PMYoussef Shoaib [MOD]
02/14/2021, 3:24 PMYoussef Shoaib [MOD]
02/14/2021, 3:25 PMreified
type parameters but lemme find a reference in the docs real quickAnimesh Sahu
02/14/2021, 3:29 PMYoussef Shoaib [MOD]
02/14/2021, 3:32 PMYoussef Shoaib [MOD]
02/14/2021, 3:37 PM