I think you’re missing a Coroutines context.
# kotlin-native
s
I think you’re missing a Coroutines context.
j
Copy code
public fun launchAndCatch(
        onError: (Throwable) -> Unit,
        function: suspend () -> Unit): Finalizable {
    val ret = Finalizable()
    val coroutineContext: CoroutineContext = Dispatchers.Main
    GlobalScope.launch(coroutineContext) {
        try {
            function()
        } catch (e: Throwable) {
            onError(e)
        } finally {
            ret.onFinally?.invoke()
        }
    }
    return ret
}
I’ve just modfied it a little to use main thread in lounchAndCatch funcion
NOw i’m trying to send context from ios code like you do, but in my generated framework there is no such class
Kotlinx_coroutines_core_nativeCoroutineDispatcher
. How can I make it compile this with a library?
s
I had the same problem as I had used the code from the KotlinConf app. The trick is to have a public property that forces the K/N header generator to include it in the framework header. IIRC when I made the ktor HTTPClient visible the coroutine types were exposed in the framework header.
j
cool! added unused property and not it’s there! 🙂 thanks
have you tried changing dispatch queue to some other, non-main?
s
I have not. It was a weekend coding project for a conference talk I did and sadly, I haven’t been able to get back to playing with it since.