pardom
02/26/2019, 4:38 PMbasher
02/26/2019, 4:39 PMpardom
02/26/2019, 4:39 PMbasher
02/26/2019, 4:40 PMpardom
02/26/2019, 4:46 PMCoroutineDispatcher
local to the test class did the trick: https://gist.github.com/pardom/74a9f1abc17688badf6b8dc06e13b1d2#file-runtimetest-kt-L13-L17nestserau
02/26/2019, 4:50 PMexpect fun <T> runBlocking(block: suspend () -> T): T
ios
actual fun <T> runBlocking(block: suspend () -> T): T {
val expectation = Expectation<T>()
GlobalScope.launch(MainRunLoopDispatcher) {
expectation.fulfill(block.invoke())
}
return expectation.wait() ?: throw RuntimeException("runBlocking failed")
}
private object MainRunLoopDispatcher : CoroutineDispatcher() {
override fun dispatch(context: CoroutineContext, block: Runnable) {
NSRunLoop.mainRunLoop().performBlock {
block.run()
}
}
}
android
actual fun <T> runBlocking(block: suspend () -> T): T = kotlinx.coroutines.runBlocking { block.invoke() }
I’m not the original author, but I don’t remember the original author unfortunately. Hope that helps.jw
02/26/2019, 4:50 PMrusshwolf
02/26/2019, 4:50 PMjw
02/26/2019, 4:50 PM@Test suspend fun
lands thoughrusshwolf
02/26/2019, 4:52 PM@Test suspend
has more details on workarounds: https://youtrack.jetbrains.com/issue/KT-22228jw
02/26/2019, 4:54 PM