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 {
6060// Register adds a client to the stream to receive all broadcast
6161// messages. Has no effect if the client is already registered.
6262func (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.
9496func (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.
108113func (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 {
You can’t perform that action at this time.
0 commit comments