https://kotlinlang.org logo
#coroutines
Title
# coroutines
t

timrijckaert

11/13/2018, 4:49 PM
How can I test a suspending function in multiplatform? Suppose I have following function:
Copy code
suspend fun CoroutineScope.foo() : ReceiveChannel<List<Int>> =
    produce {
        launch {
            val cache = cache.getCachedInts()
            offer(cache)
        }
        launch {
            val network = network.getNetworkInts
    
            if (network.isNotEmty()) {
                cache.cacheInts(network)
            }
    
            offer(network)
        }
    }
I tried
runBlocking
but it seems unavaible in MPP?
g

gildor

11/13/2018, 5:04 PM
Yes, runBlocking is not available because of JS
m

mersan

11/13/2018, 5:07 PM
you can use
Dispatchers.Unconfined
to run it on the current thread.
t

timrijckaert

11/13/2018, 5:18 PM
Copy code
GlobalScope.launch(Dispatchers.Unconfined) {
            ...
}
like this you mean?
m

mersan

11/13/2018, 8:56 PM
Yes