Skip to content

Commit

Permalink
Recover from send on closed channel
Browse files Browse the repository at this point in the history
  • Loading branch information
beatgammit committed Jan 16, 2017
1 parent 4a4b738 commit 001aac8
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ func (s *localPeer) Receive() <-chan Message {
return s.incoming
}

func (s *localPeer) Send(msg Message) error {
func (s *localPeer) Send(msg Message) (err error) {
defer func() {
// just in case Close is called before Send
err = recover()
}()
s.outgoing <- msg
return nil
return
}

func (s *localPeer) Close() error {
close(s.outgoing)
if s.outgoing != nil {
close(s.outgoing)
s.outgoing = nil
}
return nil
}

0 comments on commit 001aac8

Please sign in to comment.