Commit 59ebcbc1 authored by alexstocks's avatar alexstocks

add once for done

parent 89139c56
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
- 2016/08/24 - 2016/08/24
> delete session.go:Session:wg(atomic.WaitGroup). Add session.go:Session:grNum instead to prevent from (Session)Close() block on session.go:Session:wg.Wait() > delete session.go:Session:wg(atomic.WaitGroup). Add session.go:Session:grNum instead to prevent from (Session)Close() block on session.go:Session:wg.Wait()
> add once for session.go:Session:done(chan struct{})
> version: 0.2.05 > version: 0.2.05
- 2016/08/23 - 2016/08/23
......
...@@ -84,6 +84,7 @@ type Session struct { ...@@ -84,6 +84,7 @@ type Session struct {
*gettyConn *gettyConn
pkgHandler ReadWriter pkgHandler ReadWriter
listener EventListener listener EventListener
once sync.Once
done chan struct{} done chan struct{}
readerDone chan struct{} // end reader readerDone chan struct{} // end reader
...@@ -239,7 +240,8 @@ func (this *Session) stop() { ...@@ -239,7 +240,8 @@ func (this *Session) stop() {
case <-this.done: case <-this.done:
return return
default: default:
close(this.done) // defeat "panic: close of closed channel"
this.once.Do(func() { close(this.done) })
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment