How can the client poll the server? #12
Answered
by
Splizard
SteveMaybe
asked this question in
Q&A
-
Is it possible to configure a Seed such that it polls the server periodically to update itself, or is there a way to push updates to the clients state? |
Beta Was this translation helpful? Give feedback.
Answered by
Splizard
Jan 17, 2021
Replies: 1 comment 2 replies
-
Yes this how to do it. package main
import (
"time"
"qlova.org/seed"
"qlova.org/seed/client"
"qlova.org/seed/client/clientside"
"qlova.org/seed/client/poll"
"qlova.org/seed/new/app"
"qlova.org/seed/new/text"
)
//NewServerTime returns a text seed that is updated with the time from the server every second.
func NewServerTime(options ...seed.Option) seed.Seed {
//Create a clientside string that is stored on the client.
ServerTime := new(clientside.String)
return text.New(
text.SetStringTo(ServerTime),
poll.Every(time.Second, client.Run(func() client.Script {
return ServerTime.Set(time.Now().String())
})),
//Pass through any options.
seed.Options(options),
)
}
func main() {
app.New("Polling Example",
NewServerTime(),
).Launch()
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
Splizard
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes this how to do it.