knowyt/server/engine/engine.go
2021-07-30 16:16:55 +02:00

34 lines
582 B
Go

package engine
import (
"fmt"
"github.com/imkira/go-observer"
"sirlab.de/go/knyt/handler"
"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)
fmt.Printf("sleep: %d\n", value.VersionRef)
time.Sleep(1 * time.Second)
value.VersionRef++
engine.obs.Update(value)
}
}
func (engine *Engine) GetHttpHandler() handler.HandlerFunc {
return handler.SyncFactory(engine.obs)
}