Skip to content

Commit 4b03a23

Browse files
committed
more mutex
1 parent 55469ab commit 4b03a23

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stream.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ func NewStream() *Stream {
6060
// Register adds a client to the stream to receive all broadcast
6161
// messages. Has no effect if the client is already registered.
6262
func (s *Stream) Register(c *Client) {
63+
s.listLock.Lock()
64+
defer s.listLock.Unlock()
6365

6466
// see if the client has been registered
6567
if _, found := s.clients[c]; found {
@@ -92,6 +94,9 @@ func (s *Stream) Broadcast(e *Event) {
9294
// to this topic. Subscribe will also Register an unregistered
9395
// client.
9496
func (s *Stream) Subscribe(topic string, c *Client) {
97+
s.listLock.Lock()
98+
defer s.listLock.Unlock()
99+
95100
// see if the client is registered
96101
topics, found := s.clients[c]
97102

@@ -106,6 +111,8 @@ func (s *Stream) Subscribe(topic string, c *Client) {
106111

107112
// Unsubscribe removes clients from the topic, but not from broadcasts.
108113
func (s *Stream) Unsubscribe(topic string, c *Client) {
114+
s.listLock.Lock()
115+
defer s.listLock.Unlock()
109116

110117
topics, found := s.clients[c]
111118
if !found {

0 commit comments

Comments
 (0)