Skip to content

Instantly share code, notes, and snippets.

@omkar-tenkale
Created May 7, 2023 19:47
Show Gist options
  • Save omkar-tenkale/a1ea1f20133f2a60cc33340877bbc92d to your computer and use it in GitHub Desktop.
Save omkar-tenkale/a1ea1f20133f2a60cc33340877bbc92d to your computer and use it in GitHub Desktop.
import kotlin.coroutines.Continuation
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
import kotlin.coroutines.intrinsics.createCoroutineUnintercepted
fun launch(block: suspend () -> Unit) {
val callback = object : Continuation<Unit> {
override val context: CoroutineContext = EmptyCoroutineContext
override fun resumeWith(result: Result<Unit>) {}
}
block.createCoroutineUnintercepted(callback).resumeWith(Result.success(Unit))
}
fun main(){
launch{
greet()
}
}
suspend fun greet(){
println("Hello World!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment