wrap close(wait) with sync.Once to avoid panic
This commit is contained in:
parent
8ddd12d144
commit
cd4571f0b0
@ -81,18 +81,23 @@ func ReaderParamEncoder(addr string) jsonrpc.Option {
|
|||||||
type waitReadCloser struct {
|
type waitReadCloser struct {
|
||||||
io.ReadCloser
|
io.ReadCloser
|
||||||
wait chan struct{}
|
wait chan struct{}
|
||||||
|
closeOnce sync.Once
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *waitReadCloser) Read(p []byte) (int, error) {
|
func (w *waitReadCloser) Read(p []byte) (int, error) {
|
||||||
n, err := w.ReadCloser.Read(p)
|
n, err := w.ReadCloser.Read(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
w.closeOnce.Do(func() {
|
||||||
close(w.wait)
|
close(w.wait)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *waitReadCloser) Close() error {
|
func (w *waitReadCloser) Close() error {
|
||||||
|
w.closeOnce.Do(func() {
|
||||||
close(w.wait)
|
close(w.wait)
|
||||||
|
})
|
||||||
return w.ReadCloser.Close()
|
return w.ReadCloser.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user