this is probably the basics but I just want some guidance on how to do this so I don't spend time finding and experimenting with wrong or outdated solutions. I'm developing a library to be used from ios (and other platforms). And I want to take advantage of the suspend ecosystem. But my toplevel public api can't have suspend functions because they can't be called from swift. So the question is, what is the correct way to launch a corroutine? We have tried a few things but have always bumped into the MutabilityException and friends. Can someone tell me the correct way to do this? Or just point me to an article.
We are currently doing this
@SharedImmutable
private val DISPATCHER = kotlinx.coroutines.newSingleThreadContext("sdk-event-loop")
actual fun launchTask(task: suspend CoroutineScope.() -> Unit): Job {
val scope = CoroutineScope(DISPATCHER)
task.freeze()
return scope.launch {
println("running task on iOS! with nsrunloop dispatcher")
task()
println("done running task on iOS!")
}
}
I know how the rules of the kotlin/native runtime, but I can't use them to guide me to a solution to this problem