Skip to content

Commit

Permalink
Resolve concurrent map issue
Browse files Browse the repository at this point in the history
  • Loading branch information
chacha912 committed May 23, 2023
1 parent dbcec29 commit f8a1576
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 1 addition & 4 deletions server/backend/sync/memory/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ func (c *Coordinator) Subscribe(
return nil, nil, err
}

var peers []types.Client
for _, sub := range c.pubSub.subscriptionsMapByDocID[documentID].Map() {
peers = append(peers, sub.Subscriber())
}
peers := c.pubSub.GetPeers(documentID)
return sub, peers, nil
}

Expand Down
12 changes: 12 additions & 0 deletions server/backend/sync/memory/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,18 @@ func (m *PubSub) Publish(
}
}

// GetPeers returns the peers of the given document.
func (m *PubSub) GetPeers(documentID types.ID) []types.Client {
m.subscriptionsMapMu.RLock()
defer m.subscriptionsMapMu.RUnlock()

var peers []types.Client
for _, sub := range m.subscriptionsMapByDocID[documentID].Map() {
peers = append(peers, sub.Subscriber())
}
return peers
}

// UpdatePresence updates the presence of the given client.
func (m *PubSub) UpdatePresence(
publisher *types.Client,
Expand Down

0 comments on commit f8a1576

Please sign in to comment.