https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
t

Tiago Nunes

05/31/2021, 4:40 PM
Hey everyone, is there a way to launch coroutines in Swift? I have this function in shared:
Copy code
suspend fun wait() = withContext(Dispatchers.Default) {
    delay(1000)
    true
}
How do I call this in Swift? I know I can launch a coroutine in shared and provide callbacks (and then call this in swift):
Copy code
fun waitIos(onFinished: OnFinishedCallback) = GlobalScope.launch {
    val result = wait()
    onFinished.finish(result)
}
But this way I need to write lots of wrappers and use callbacks, which kind of takes the fun out of using coroutines... (in the ios side) It makes sense if it isn't possible, I just want to make sure that it really isn't
it has some caveats/limitations but might be useful for you
t

Tiago Nunes

05/31/2021, 4:53 PM
@*John O'Reilly* Interesting... and when I call queryData it starts a coroutine and returns the job?
j

John O'Reilly

05/31/2021, 4:54 PM
you don't unfortunately have that level of control....following goes through some of the limitations etc https://dev.to/touchlab/kotlin-1-4-suspend-functions-209
t

Tiago Nunes

05/31/2021, 5:04 PM
That's probably the most misterious article I've read 😅 Thanks, I'll probably stay away from the feature, and hope that it gets better soon 🙂
r

ribesg

06/01/2021, 11:18 AM
I just don’t write Swift 😄
2 Views