tseisel
04/04/2019, 9:31 AMsuspend fun
suspends until a certain condition is met ?
I tried the following :
runBlocking() {
val testSource = BehaviorProcessor.create<String>()
val subjectUnderTest = MyCache(coroutineScope = this, source = testSource)
val loading = async(start = CoroutineStart.UNDISPATCHED) { subjectUnderTest.getCachedValue() } // Suspend function call
assertFalse(loading.isCompleted)
// Sending an element to that processor satisfies the condition
testSource.onNext("Foo")
assertTrue(loading.isCompleted) // This fails : isCompleted is false
}
gildor
04/04/2019, 9:36 AMtseisel
04/04/2019, 9:44 AMBehaviorProcessor
it depends on.
The only way I thought of was using async, as calling the suspending function may block the test indefinitely, so I wouldn't be able to satisfy the condition.