Skip to content

Commit

Permalink
add emit config update helper (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
paulwe authored Mar 13, 2024
1 parent 912f0cf commit 8d755b4
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions utils/configobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ func (c *ConfigObserver[T]) Close() {
}
}

func (c *ConfigObserver[T]) EmitConfigUpdate(conf *T) {
c.mu.Lock()
defer c.mu.Unlock()
for e := c.cbs.Front(); e != nil; e = e.Next() {
go e.Value.(func(*T))(conf)
}
}

func (c *ConfigObserver[T]) Observe(cb func(*T)) func() {
if c == nil {
return func() {}
Expand Down Expand Up @@ -106,11 +114,7 @@ func (c *ConfigObserver[T]) reload(path string) error {
return err
}

c.mu.Lock()
defer c.mu.Unlock()
for e := c.cbs.Front(); e != nil; e = e.Next() {
go e.Value.(func(*T))(conf)
}
c.EmitConfigUpdate(conf)
return nil
}

Expand Down

0 comments on commit 8d755b4

Please sign in to comment.