Nikolay Kasyanov
08/31/2021, 3:02 PMcompletionHandler
not on the same thread the “coroutine” method was called on, I get illegal sharing exception:
class DependencyImpl: FooBarDependency {
func getName(completionHandler: @escaping (String?, Error?) -> Void) {
...
}
}
When thread stays the same, it’s all good. I’m using coroutines 1.5.1-native-mt.
Kotlin code in comments.class FooBar(val dependency: Dependency) {
interface Dependency {
suspend fun getName(): String
}
fun doStuff(callback: (String) -> Unit): Disposable {
val suspendCall: suspend () -> String = dependency::getName
return suspendCall
.asSingle()
.subscribeOn(ioScheduler)
.observeOn(mainScheduler)
.map { "Hello $it" }
.subscribe {
callback(it)
}
}
}
russhwolf
08/31/2021, 3:35 PMNikolay Kasyanov
09/01/2021, 7:38 AMAlexander Ignatiev
09/01/2021, 8:17 AMDispatchQueue.main.async {
completionHandler()
}
Nikolay Kasyanov
09/02/2021, 8:04 AM