I have `class` that takes a `suspend` function, `p...
# multiplatform
a
I have
class
that takes a
suspend
function,
passedFn
, as a parameter. And the class has a
suspend
method,
fn()
. When
fn()
calls
passedFn()
I receive this error on iOS
illegal attempt to access non-shared Something.$fnCOROUTINE$0@2d9f788 from other thread.
I'm vaguely aware it has something to do with freezing objects across threads. Could anyone enlighten me further? What would I need to do in order to get this to work?
Kotlin
Copy code
class Something(
  val passedFn: suspend () -> Unit,
) {
  suspend fun fn(): Boolean {
    passedFn() // crash here
    return true
  }
}
Swift
Copy code
class AFunction : KotlinSuspendFunction0 {
  func invoke() async throws -> Any? {
    return nil
  }
}
Something(myfn: AFunction()).fn() { v, e in
  print("hello \(v)")
}
m
are you using the new memory model?
a
I just put
kotlin.native.binary.memoryModel=experimental
is my gradle properties and now it's all working. Thanks you enormously
👍 1