File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,8 @@ func NewStream() *Stream {
60
60
// Register adds a client to the stream to receive all broadcast
61
61
// messages. Has no effect if the client is already registered.
62
62
func (s * Stream ) Register (c * Client ) {
63
+ s .listLock .Lock ()
64
+ defer s .listLock .Unlock ()
63
65
64
66
// see if the client has been registered
65
67
if _ , found := s .clients [c ]; found {
@@ -92,6 +94,9 @@ func (s *Stream) Broadcast(e *Event) {
92
94
// to this topic. Subscribe will also Register an unregistered
93
95
// client.
94
96
func (s * Stream ) Subscribe (topic string , c * Client ) {
97
+ s .listLock .Lock ()
98
+ defer s .listLock .Unlock ()
99
+
95
100
// see if the client is registered
96
101
topics , found := s .clients [c ]
97
102
@@ -106,6 +111,8 @@ func (s *Stream) Subscribe(topic string, c *Client) {
106
111
107
112
// Unsubscribe removes clients from the topic, but not from broadcasts.
108
113
func (s * Stream ) Unsubscribe (topic string , c * Client ) {
114
+ s .listLock .Lock ()
115
+ defer s .listLock .Unlock ()
109
116
110
117
topics , found := s .clients [c ]
111
118
if ! found {
You can’t perform that action at this time.
0 commit comments