safe data for continues
This commit is contained in:
parent
ed53d1bae7
commit
dd98f656d1
|
@ -3,6 +3,7 @@ package respondd
|
|||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/FreifunkBremen/yanic/data"
|
||||
"github.com/FreifunkBremen/yanic/lib/duration"
|
||||
|
@ -26,6 +27,7 @@ type Daemon struct {
|
|||
Babel string `toml:"babel"`
|
||||
babelData *babelState.BabelState `toml:"-"`
|
||||
|
||||
dataMX sync.Mutex
|
||||
dataByInterface map[string]*data.ResponseData
|
||||
|
||||
Answer *AnswerConfig `toml:"defaults"`
|
||||
|
|
|
@ -22,6 +22,8 @@ func (d *Daemon) updateData() {
|
|||
}
|
||||
|
||||
func (d *Daemon) getData(iface string) *data.ResponseData {
|
||||
d.dataMX.Lock()
|
||||
defer d.dataMX.Unlock()
|
||||
if iData, ok := d.dataByInterface[iface]; ok {
|
||||
return iData
|
||||
}
|
||||
|
|
|
@ -16,7 +16,9 @@ func (d *Daemon) Start() {
|
|||
d.AnswerByZones = make(map[string]*AnswerConfig)
|
||||
}
|
||||
|
||||
d.dataMX.Lock()
|
||||
d.updateData()
|
||||
d.dataMX.Unlock()
|
||||
go d.updateWorker()
|
||||
|
||||
if d.Babel != "" {
|
||||
|
@ -69,6 +71,8 @@ func (d *Daemon) updateWorker() {
|
|||
c := time.Tick(d.DataInterval.Duration)
|
||||
|
||||
for range c {
|
||||
d.dataMX.Lock()
|
||||
d.updateData()
|
||||
d.dataMX.Unlock()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue