refactoring
This commit is contained in:
parent
56cd5b4698
commit
caa1c06ccf
@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"github.com/imkira/go-observer"
|
||||
"sirlab.de/go/knyt/handler"
|
||||
"sirlab.de/go/knyt/syncdata"
|
||||
"time"
|
||||
)
|
||||
|
||||
@ -13,14 +14,14 @@ type Engine struct {
|
||||
|
||||
func NewEngine() *Engine {
|
||||
engine := Engine{
|
||||
obs: observer.NewProperty(handler.Value{}),
|
||||
obs: observer.NewProperty(syncdata.SyncData{}),
|
||||
}
|
||||
return &engine
|
||||
}
|
||||
|
||||
func (engine *Engine) Run() {
|
||||
for {
|
||||
value := engine.obs.Value().(handler.Value)
|
||||
value := engine.obs.Value().(syncdata.SyncData)
|
||||
fmt.Printf("sleep: %d\n", value.VersionRef)
|
||||
time.Sleep(1 * time.Second)
|
||||
value.VersionRef++
|
||||
|
@ -5,13 +5,10 @@ import (
|
||||
"fmt"
|
||||
"github.com/imkira/go-observer"
|
||||
"net/http"
|
||||
"sirlab.de/go/knyt/syncdata"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Value struct {
|
||||
VersionRef int `json:"version"`
|
||||
}
|
||||
|
||||
func SyncFactory(obs observer.Property) HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
versionRef, err := strconv.Atoi(r.URL.Query().Get("v"))
|
||||
@ -20,9 +17,9 @@ func SyncFactory(obs observer.Property) HandlerFunc {
|
||||
}
|
||||
|
||||
stream := obs.Observe()
|
||||
var value Value
|
||||
var value syncdata.SyncData
|
||||
for {
|
||||
value = stream.Value().(Value)
|
||||
value = stream.Value().(syncdata.SyncData)
|
||||
if value.VersionRef >= versionRef {
|
||||
break
|
||||
}
|
||||
|
5
server/syncdata/syncdata.go
Normal file
5
server/syncdata/syncdata.go
Normal file
@ -0,0 +1,5 @@
|
||||
package syncdata
|
||||
|
||||
type SyncData struct {
|
||||
VersionRef int `json:"version"`
|
||||
}
|
Loading…
Reference in New Issue
Block a user