Hello, ``` @Test fun example() = runBlocki...
# coroutines
p
Hello,
Copy code
@Test
    fun example() = runBlocking {
        val a = produce {
            var i = 0
            while (isActive) {
                send(i++)
                delay(100)
            }
        }
        val b = a.broadcast(start = CoroutineStart.DEFAULT)

        launch {
            b.consumeEach {
                println("A: $it")
            }
        }
        
        b.close()

        delay(1_000)
    }
When I close b broadcast channel I get an exception:
Copy code
Exception in thread "Test worker @coroutine#3" kotlinx.coroutines.channels.ClosedSendChannelException: Channel was closed (Coroutine boundary)
Is this the expected behavior?
d
Yes. The coroutine was unconditionally waiting for the channel and the only way to interrupt it is with an exception.
a
exception is thrown at send()
seems like producer still produces values and doesn't react to broadcast close()
p
Copy code
val a = produce { while (isActive) send(1) }
        val b = a.broadcast(start = CoroutineStart.DEFAULT)
        b.close()
also throws an exception
d
Does,
Copy code
val a = produce { while (isActive) send(1) }
a.close()
throw an exception? (Not on computer to check)
p
produce return a ReceiveChannel. ReceiveChannel does not have a close operation. If I call a.cancel() it works. But what I really want to understand if this is a bug in coroutines because it seems like one.