Closed
Description
I have proposed this before (#15411), but at the time Go2 wasn't anywhere near planned.
The problem
- In multi-writers/readers situations, the user has to use an extra channel or
context.Context
. - Users either implement their minimal version of
Context
or useContext
with the slight overhead just as a safe channel barrier.
The proposal
- Allow
close(ch)
to always succeed. - Allow:
select {
case ok := ch <- val:
if !ok { exit logic }
case ch <- val: // this still panics if the channel is closed.
}
Go 1 compat
The the 2nd part of the proposal is 100% compatible with Go1, it will not break any current code since the syntax wouldn't be used in any older projects, the 1st part however can be iffy if you have tools that depend on the panic (I don't know any)
This also can also solve #27982.