knowyt/server/engine/engine.go

35 lines
620 B
Go
Raw Normal View History

2021-07-29 19:06:25 +00:00
package engine
import (
"fmt"
"github.com/imkira/go-observer"
2021-07-30 14:16:55 +00:00
"sirlab.de/go/knyt/handler"
2021-07-30 19:49:18 +00:00
"sirlab.de/go/knyt/syncdata"
2021-07-29 19:06:25 +00:00
"time"
)
type Engine struct {
obs observer.Property
}
func NewEngine() *Engine {
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)
}
}
func (engine *Engine) GetHttpHandler() handler.HandlerFunc {
return handler.SyncFactory(engine.obs)
}