Skip to content

Commit

Permalink
fixed close support for http.Subscriber
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Nov 12, 2018
1 parent 61ff189 commit 6d55e95
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions message/infrastructure/http/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewSubscriber(addr string, unmarshalMessageFunc UnmarshalMessageFunc, logge
s,
logger,
unmarshalMessageFunc,
make([]chan *message.Message, 1),
make([]chan *message.Message, 0),
&sync.Mutex{},
false,
}, nil
Expand Down Expand Up @@ -84,17 +84,19 @@ func (s *Subscriber) RunHTTPServer() error {
return s.server.ListenAndServe()
}

func (s Subscriber) Close() error {
func (s *Subscriber) Close() error {
if s.closed {
return nil
}
s.closed = true

defer func() {
for _, ch := range s.outputChannels {
close(ch)
}
}()
if err := s.server.Close(); err != nil {
return err
}

for _, ch := range s.outputChannels {
close(ch)
}

return s.server.Close()
return nil
}

0 comments on commit 6d55e95

Please # to comment.