How can I test a suspending function in multiplatf...
# coroutines
t
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
Yes, runBlocking is not available because of JS
m
you can use
Dispatchers.Unconfined
to run it on the current thread.
t
Copy code
GlobalScope.launch(Dispatchers.Unconfined) {
            ...
}
like this you mean?
m
Yes