kasper.kondzielski
03/03/2018, 12:25 PMchannel
.
For now I have something like that:
@Test
fun watcherShoulbBeInvokedTwice() = runBlocking {
val watcher = createWatcher()
triggerFirstResponse()
val channel = watcher.await(coroutineContext)
for (data in channel) {
println(data)
}
triggerSecondResponse()
}
And my await function looks like this:
fun <T> Watcher<T>.await(coroutineContext: CoroutineContext) = produce<T>(capacity = Channel.UNLIMITED, context = coroutineContext) {
val callback = object : Callback<T>() {
override fun onResponse(response: Response<T>) {
if (isActive) {
offer(response.data()!!)
}
}
override fun onFailure(e: ApolloException) {
if (isActive) {
throw e
}
}
}
enqueueAndWatch(callback)
}
But I cannot make my tests to print two responses