knowyt/server/src/engine/engine.go

35 lines
535 B
Go
Raw Normal View History

2021-07-29 19:06:25 +00:00
package engine
import (
"github.com/imkira/go-observer"
2021-07-30 19:49:18 +00:00
"sirlab.de/go/knyt/syncdata"
2021-07-29 19:06:25 +00:00
"time"
)
func NewEngine() *Engine {
2021-07-29 19:06:25 +00:00
engine := Engine{
2021-08-09 07:47:52 +00:00
versionRef: 0,
obs: observer.NewProperty(syncdata.SyncData{}),
notify: make(chan bool, 2),
2021-07-29 19:06:25 +00:00
}
2021-07-29 19:06:25 +00:00
return &engine
}
func (eng *Engine) Run(populateSyncDataCb PopulateSyncDataCb) {
2021-07-29 19:06:25 +00:00
for {
select {
case <-eng.notify:
// nop
case <-time.After(15 * time.Second):
// nop
2021-08-04 23:42:21 +00:00
}
2021-08-09 07:47:52 +00:00
eng.publish(populateSyncDataCb)
2021-08-09 08:36:19 +00:00
}
}
func (eng *Engine) Update() {
eng.notify <- true
}