knowyt/server/engine/engine.go

34 lines
582 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-29 19:06:25 +00:00
"time"
)
type Engine struct {
obs observer.Property
}
func NewEngine() *Engine {
engine := Engine{
obs: observer.NewProperty(handler.Value{}),
}
return &engine
}
func (engine *Engine) Run() {
for {
value := engine.obs.Value().(handler.Value)
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)
}