With the new MM, will coroutines `1.6.0` support c...
# coroutines
h
With the new MM, will coroutines
1.6.0
support calling suspend functions (and flow collect) from other iOS threads?
👀 8
m
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
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
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
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.