knowyt/server/src/engine/engine.go
2021-08-13 01:07:06 +02:00

35 lines
535 B
Go

package engine
import (
"github.com/imkira/go-observer"
"sirlab.de/go/knyt/syncdata"
"time"
)
func NewEngine() *Engine {
engine := Engine{
versionRef: 0,
obs: observer.NewProperty(syncdata.SyncData{}),
notify: make(chan bool, 2),
}
return &engine
}
func (eng *Engine) Run(populateSyncDataCb PopulateSyncDataCb) {
for {
select {
case <-eng.notify:
// nop
case <-time.After(15 * time.Second):
// nop
}
eng.publish(populateSyncDataCb)
}
}
func (eng *Engine) Update() {
eng.notify <- true
}