2021-07-29 19:06:25 +00:00
|
|
|
package engine
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"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-04 22:52:35 +00:00
|
|
|
func NewEngine(id string) *Engine {
|
2021-07-29 19:06:25 +00:00
|
|
|
engine := Engine{
|
2021-07-30 19:49:18 +00:00
|
|
|
obs: observer.NewProperty(syncdata.SyncData{}),
|
2021-07-29 19:06:25 +00:00
|
|
|
}
|
|
|
|
return &engine
|
|
|
|
}
|
|
|
|
|
|
|
|
func (engine *Engine) Run() {
|
|
|
|
for {
|
2021-07-30 19:49:18 +00:00
|
|
|
value := engine.obs.Value().(syncdata.SyncData)
|
2021-07-29 19:14:54 +00:00
|
|
|
fmt.Printf("sleep: %d\n", value.VersionRef)
|
2021-07-29 19:06:25 +00:00
|
|
|
time.Sleep(1 * time.Second)
|
2021-07-29 19:14:54 +00:00
|
|
|
value.VersionRef++
|
2021-07-29 19:06:25 +00:00
|
|
|
engine.obs.Update(value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 22:52:35 +00:00
|
|
|
func (engine *Engine) GetHttpHandler() HandleFunc {
|
|
|
|
return SyncFactory(engine.obs)
|
2021-07-29 19:06:25 +00:00
|
|
|
}
|