mirror of
https://github.com/coder/coder.git
synced 2026-06-02 20:48:20 +00:00
fix: address nats callback review comments
This commit is contained in:
@@ -143,6 +143,7 @@ func routesWithAuth(routes []*url.URL, token string) []*url.URL {
|
||||
return withAuth
|
||||
}
|
||||
|
||||
// sortedURLsEqual assumes sorted slices.
|
||||
func sortedURLsEqual(a, b []*url.URL) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
|
||||
@@ -107,8 +107,6 @@ func replicaNATSPeerAddresses(rm *replicasync.Manager) []string {
|
||||
if replica.RelayAddress == "" {
|
||||
continue
|
||||
}
|
||||
// coderd/x/nats accepts relay-style URLs here and normalizes the host
|
||||
// to the NATS route port.
|
||||
addresses = append(addresses, replica.RelayAddress)
|
||||
}
|
||||
return addresses
|
||||
|
||||
@@ -359,11 +359,7 @@ func (m *Manager) syncReplicas(ctx context.Context) error {
|
||||
}
|
||||
}
|
||||
m.self = replica
|
||||
callbacks := make([]func(), 0, len(m.callbacks))
|
||||
for _, callback := range m.callbacks {
|
||||
callbacks = append(callbacks, callback)
|
||||
}
|
||||
for _, callback := range callbacks {
|
||||
go callback()
|
||||
}
|
||||
return nil
|
||||
@@ -448,16 +444,15 @@ func (m *Manager) regionID() int32 {
|
||||
// callback. Passing nil removes the named callback.
|
||||
func (m *Manager) SetCallback(name string, callback func()) {
|
||||
m.mutex.Lock()
|
||||
defer m.mutex.Unlock()
|
||||
if callback == nil {
|
||||
delete(m.callbacks, name)
|
||||
m.mutex.Unlock()
|
||||
return
|
||||
}
|
||||
if m.callbacks == nil {
|
||||
m.callbacks = make(map[string]func())
|
||||
}
|
||||
m.callbacks[name] = callback
|
||||
m.mutex.Unlock()
|
||||
// Instantly call the callback to inform replicas!
|
||||
go callback()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user