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

bj0

12/08/2017, 4:20 PM
instead of
while / try / receive
you can just use a
for
loop over
channel
. As for testing,
runBlocking
is generally used to make the function wait until the coroutines are done.
k

koufa

12/09/2017, 11:06 AM
Yes I have changed it to use
consumeEach
to not have to handle the close excpetion myself. But the question how to test this remains. I am using
runBlocking
but I have an issue regarding the timing of mocking
send
events to the
channel
and the assertion on the
LiveData
instance. @elizarov Do you have some suggestion on this?
Ok I tried it with mocking the channel using a buffered
channel
and after the mocked
send
calls I use
close
and it works. I didnt knew that
close
waits all items to be consumed before closing the channel
5 Views