-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Broadcast close with CoroutineStart.DEFAULT produces an unexpected exception #1713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Why would you expect the sender to suspend instead of throwing an exception? See, conceptually |
I see what you are saying but if we have the same example just with CoroutineStart.LAZY runBlocking {
val a = produce {
while (true) send(1)
}
val b = a.broadcast()
b.close()
} In this case |
That looks like a bug. Should be the same with lazy -- closing the broadcast channel should be closing the original channel. |
to clarify a bit: when close() is called:
Currently it is:
fun <E> ReceiveChannel<E>.broadcast(
capacity: Int = 1,
start: CoroutineStart = CoroutineStart.LAZY
): BroadcastChannel<E> =
GlobalScope.broadcast(Dispatchers.Unconfined,
capacity = capacity,
start = start,
onCompletion = consumes()) {
for (e in this@broadcast) {
send(e)
}
} |
Documentation on broadcast operators is added that explain the the resulting BroadcastChannel shall be cancelled if it is not needed anymore. Fixes #1713
* Documentation on broadcast operators is added that explains that the resulting BroadcastChannel shall be cancelled if it is not needed anymore. * More tests added for various broadcast cancel/close cases. * The only functional change is that closing a broadcast channel for lazy coroutine shall start the corresponding coroutine to give it a chance to promptly fail. * Mark broadcast operators as obsolete. To be replaced with sharing operators on flows (see #1716). Fixes #1713
Some additional explanaition here. When you |
* Documentation on broadcast operators is added that explains that the resulting BroadcastChannel shall be cancelled if it is not needed anymore. * More tests added for various broadcast cancel/close cases. * The only functional change is that closing a broadcast channel for lazy coroutine shall start the corresponding coroutine to give it a chance to promptly fail. * Mark broadcast operators as obsolete. To be replaced with sharing operators on flows (see #1716). Fixes #1713
* Documentation on broadcast operators is added that explains that the resulting BroadcastChannel shall be cancelled if it is not needed anymore. * More tests added for various broadcast cancel/close cases. * The only functional change is that closing a broadcast channel for lazy coroutine shall start the corresponding coroutine to give it a chance to promptly fail. * Mark broadcast operators as obsolete. To be replaced with sharing operators on flows (see #1716). Fixes #1713
* Documentation on broadcast operators is added that explains that the resulting BroadcastChannel shall be cancelled if it is not needed anymore. * More tests added for various broadcast cancel/close cases. * The only functional change is that closing a broadcast channel for lazy coroutine shall start the corresponding coroutine to give it a chance to promptly fail. * Mark broadcast operators as obsolete. To be replaced with sharing operators on flows (see #1716). Fixes #1713
Kotlin: 1.3.61
Coroutines: 1.3.3
Problem:
send(1)
throws an exception afterb.close()
is called.Expected behavior:
send(1)
should suspend instead of throwing an exception.The text was updated successfully, but these errors were encountered: