Skip to content

Commit

Permalink
call config observers synchronously (#657)
Browse files Browse the repository at this point in the history
* call config observers synchronously

* cleanup
  • Loading branch information
paulwe authored Mar 14, 2024
1 parent a9939bc commit feb177f
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 @@ -2,6 +2,7 @@ package utils

import (
"container/list"
"fmt"
"os"
"sync"

Expand Down Expand Up @@ -61,7 +62,7 @@ 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)
e.Value.(func(*T))(conf)
}
}

Expand Down Expand Up @@ -125,14 +126,17 @@ func (c *ConfigObserver[T]) load(path string) (*T, error) {
}

if path != "" {
f, err := os.OpenFile(path, os.O_RDONLY, 0644)
b, err := os.ReadFile(path)
if err != nil {
return nil, err
}
defer f.Close()

if err := yaml.NewDecoder(f).Decode(conf); err != nil {
return nil, err
if len(b) == 0 {
return nil, fmt.Errorf("cannot parse config: file empty")
}

if err := yaml.Unmarshal(b, conf); err != nil {
return nil, fmt.Errorf("cannot parse config: %v", err)
}
}

Expand Down

0 comments on commit feb177f

Please sign in to comment.