Skip to content

Instantly share code, notes, and snippets.

@MaksimDmitriev
Created November 4, 2023 04:27
Show Gist options
  • Save MaksimDmitriev/9e20d3443d7f4060d1d5065079464121 to your computer and use it in GitHub Desktop.
Save MaksimDmitriev/9e20d3443d7f4060d1d5065079464121 to your computer and use it in GitHub Desktop.
CrossInlineSample
package ru.maksim.sample
inline fun foo(task: () -> Unit) {
println("Before task")
task()
println("After task")
}
fun callingFunction() {
foo {
println("Task is running")
return@callingFunction
}
println("After calling function")
}
inline fun foo2(crossinline task: () -> Unit) {
println("Before task2")
task()
println("After task2")
}
fun callingFunction2() {
foo2 {
println("Task is running")
// return@callingFunction2 // return not allowed here because of crossinline
}
println("After calling function")
}
class SampleTest {
@Test
fun sample() {
callingFunction()
callingFunction2()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment