matt tighe
02/27/2019, 6:32 PMThread.sleep, I’ve done the following:
class MyClass {
fun pubFun(coroutineScope: CoroutineScope = CoroutineScope(<http://Dispatchers.IO|Dispatchers.IO>): Result {
if (condition) privFun(coroutineScope)
}
private fun privFun(coroutineScope: CoroutineScope) = coroutineScope.launch {
// Do file IO
}
}
@Test
fun testPrivFun() {
//setup
val result = runBlocking { myClass.pubFun(this@runBlocking) }
}
I’ve found that this works, but I don’t totally grok what I’m doing. What if any antipatterns am I incorporating? Also, using runBlocking at the function level doesn’t create the same behavior (ie fun testPrivFun() = runBlocking { .... Why is that?
Note that the result of pubFun isn’t tied to the completion of privFun. privFun is a fire and forget call