I’m attempting to wrap some suspending functions w...
# coroutines
p
I’m attempting to wrap some suspending functions with a non-suspending call with a callback (due to Swift not currently being able to call suspending functions exposed in K/N). So far I have the following, however I seem to an exception when compiling it with
inline
but it seems to compile fine without:
Copy code
typealias ResultCallback<R> = (Result<R>) -> Unit

internal inline operator fun <R> ResultCallback<R>.invoke (
    scope: CoroutineScope = GlobalScope,
    context: CoroutineContext = EmptyCoroutineContext,
    crossinline block: suspend () -> R
) = scope.launch(context) { this@invoke(runCatching { block() }) }
example usage would be
Copy code
suspend fun greeting(name: String): String {
    delay(1000)
    return "Hello, $name"
}

fun greeting(name: String, callback: ResultCallback<String>) = callback { greeting(name) }
When `inline`’d I get the following from the compiler:
e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: wrong bytecode generated