https://kotlinlang.org logo
Title
h

hfhbd

11/19/2021, 10:34 AM
With the new MM, will coroutines
1.6.0
support calling suspend functions (and flow collect) from other iOS threads?
👀 8
m

Marc-Antoine Fortier

11/22/2021, 4:24 PM
Yes, I'm pretty sure it actually does! You can try the kmm-production-sample (New Memory-Model Demo branch). It uses ktor w/ coroutines and handles processing on background queue for both iOS & Android. 🙂
h

hfhbd

11/22/2021, 6:00 PM
Are you sure? The CFlow runs on the main dispatcher: https://github.com/Kotlin/kmm-production-sample/blob/2116cee50861559f330ad59404982ed0fae75c8d/shared/src/iosMain/kotlin/com/github/jetbrains/rssreader/core/CFlow.kt#L20 And the demo does not call any
suspend
functions from Swift.
m

Marc-Antoine Fortier

11/22/2021, 6:37 PM
True for the CFlow 👍 (which seems to be for « ui-specific state binding»), but if you check out the IOSFeedParser, it seems to be using a coroutine on the default dispatcher for xml parsing : https://github.com/Kotlin/kmm-production-sample/blob/2116cee50861559f330ad59404982[…]ain/kotlin/com/github/jetbrains/rssreader/core/IosFeedParser.kt For calling suspend functions from Swift, I may not have the answer though. 😕
h

hfhbd

11/22/2021, 7:41 PM
Sure, you can use other Dispatchers from Kotlin code, but not from Swift code. Tested again, you can't. But with Swift await/async you can use
@MainActor
, which is nice to use.