Is there any sane way to let ios implement a suspe...
# multiplatform
p
Is there any sane way to let ios implement a suspending interface? When we have an interface that suspends:
Copy code
public fun runTest(suspending: SuspendingInterface) {
  CoroutineScope(Dispatchers.Default).launch {
    println(suspending.value())
  }
}

public interface SuspendingInterface {

  public suspend fun value(): Int
}
And ios switches threads:
Copy code
class SuspendingInterfaceImpl : SuspendingInterface{
  func value(completionHandler: @escaping (KotlinInt?, Error?) -> Void) {
    DispatchQueue.global().async {
      completionHandler(42, nil)
    }
  }
}

CoroutineTest.runTest(SuspendingInterfaceImpl())
That directly fails with:
Copy code
kotlin.native.IncorrectDereferenceException: illegal attempt to access non-shared kotlinx.coroutines.internal.DispatchedContinuation@1f67dc8 from other thread
👀 1
b
p
Yep
j
p
I don't think so
To me this pretty much looks like a bug
j
Does it work if you wrap the entire call to 'value' in a dispatchqueue? Just making sure that the entire method is run on the same thread?
p
It's an example showing that suspend functions on iOS are heavily limited because you can't switch threads
j
I won't argue with you about that. 😕