https://kotlinlang.org logo
d

David W

10/09/2018, 6:19 PM
I'm seeing some really unintuitive behavior from channels.
Copy code
------------------- Code
        lateinit var intentionReceiverChannel: Channel<Intention>

        val intentionReceiver = actor<Intention>(
            capacity = 0
        ) {
                intentionReceiverChannel = channel
                // channel.flatMap { ... }.scan { ... }.consumeEach { ... }
           }

---------------------- Unit Tests
        intentionReceiver.sendBlocking(Intention())
        Assertions.assertThat(intentionReceiverChannel!!.isEmpty).isTrue() // passes
        Assertions.assertThat(intentionReceiverChannel!!.isFull).isFalse() // fails
How is the channel both full and empty at the same time? Flipping those two asserts doesn't change anything.