-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: allow send on a closed channel to gracefully fail in a select #15411
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
The current semantics are intentional. Multiple writers each independently closing a channel indicates a design problem. Neither a recover nor a language change is the solution. This has been discussed at length on various mailing lists. /cc @adg who might be able to provide references. |
This isn't a proposal of multiple writers closing the channel, this is a proposal of allowing the channel to be closed by an outside call and gracefully shutting down all the writers. Right now you can NOT close the channel if there are multiple writers, even when synchronizing with a close channel. You can use a sync.WaitGroup but this just adds overhead, unless I'm missing something obvious. |
@bradfitz
|
Let's move this discussion to the mailing list. |
@bradfitz I tried to post but it didn't go through, here's an example of what I was talking about https://go-review.googlesource.com/22315 |
@OneOfOne If you send me your e-mail address (you can send to iant@golang.org or reply here) I'll check whether you are somehow blocked on the mailing lists. |
Discussion is in: https://groups.google.com/forum/#!topic/golang-dev/I8jPg9N1p2o |
Currently, the only way to close a channel with multiple writers is to use a hacky
defer func() { recover() }()
or using a waitgroup and a counter.My proposal is to allow something like this to work without the hack:
It should still panic without the select, or an alternative syntax but I know this is highly unlikely in the 1.x cycle.
This is not about allowing multiple writers to close a channel, this is about allowing a closed channel in a multiple select situation.
Should still panic, however:
Wouldn't panic (check the CL and the test in it).
The text was updated successfully, but these errors were encountered: