Is this expected? This test fails: ``` @Test fun t...
# coroutines
m
Is this expected? This test fails:
Copy code
@Test
fun test() = runBlocking {
    assertTrue(actor<Unit> { for (it in this) {  } }.offer(Unit))
}
But this test passes:
Copy code
@Test
fun test() = runBlocking {
    val actor = GlobalScope.actor<Unit> { for (it in this) {  } }
    delay(100)
    assertTrue(actor.offer(Unit))
}
It’s like the actor’s queue needs some time to be set up. It’s not ready right away after creation.
e
It is expected. It is not about setting up queue. This is not how or why you’d use offer.
z
The first test fails because your test coroutine never gives the actor coroutine a chance to run. Your second test does this by calling
delay
, but I think you should get the same result if you just used
yield
.
offer
will only succeed if there is a coroutine that is currently suspended waiting for something from the channel. Since the actor never has a chance to run, it never receives from its channel, so the offer fails.