Martin Devillers
10/25/2018, 4:52 PM@Test
fun test() = runBlocking {
assertTrue(actor<Unit> { for (it in this) { } }.offer(Unit))
}
But this test passes:
@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.elizarov
10/25/2018, 5:15 PMZach Klippenstein (he/him) [MOD]
10/25/2018, 7:16 PMdelay
, 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.