fix write on closed chan error

master
codeskyblue 8 years ago
parent 7b68d2d2c8
commit 8abbd8e657

@ -30,7 +30,7 @@ Standalone binary can be download from one of the following addresses
| Branch | Source | Address |
|--------|--------|---------|
| stable | equinox| <https://dl.equinox.io/shengxiang/gosuv/stable> |
| stable | github | stable | <https://github.com/codeskyblue/gosuv/releases/latest>|
| stable | github | <https://github.com/codeskyblue/gosuv/releases/latest>|
| dev | equinox| <https://dl.equinox.io/shengxiang/gosuv/dev> |
Or if you have go enviroment, you can also build from source.

@ -124,9 +124,12 @@ func NopWriteCloser(w io.Writer) io.WriteCloser {
type chanStrWriter struct {
C chan string
closed bool
mu sync.Mutex
}
func (c *chanStrWriter) Write(data []byte) (n int, err error) {
c.mu.Lock()
defer c.mu.Unlock()
if c.closed {
return 0, errors.New("chan writer closed")
}
@ -135,6 +138,8 @@ func (c *chanStrWriter) Write(data []byte) (n int, err error) {
}
func (c *chanStrWriter) Close() error {
c.mu.Lock()
defer c.mu.Unlock()
if !c.closed {
c.closed = true
close(c.C)

Loading…
Cancel
Save