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"
|
|
|
|
)
|
|
|
|
|
2021-08-09 14:24:27 +00:00
|
|
|
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{}),
|
2021-08-09 14:24:27 +00:00
|
|
|
notify: make(chan bool, 2),
|
2021-07-29 19:06:25 +00:00
|
|
|
}
|
2021-08-09 14:24:27 +00:00
|
|
|
|
2021-07-29 19:06:25 +00:00
|
|
|
return &engine
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:24:27 +00:00
|
|
|
func (eng *Engine) Run(populateSyncDataCb PopulateSyncDataCb) {
|
2021-07-29 19:06:25 +00:00
|
|
|
for {
|
2021-08-09 14:24:27 +00:00
|
|
|
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
|
|
|
|
2021-08-09 14:24:27 +00:00
|
|
|
eng.publish(populateSyncDataCb)
|
2021-08-09 08:36:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 14:24:27 +00:00
|
|
|
func (eng *Engine) Update() {
|
|
|
|
eng.notify <- true
|
|
|
|
}
|