Skip to content

How can the client poll the server? #12

Answered by Splizard
SteveMaybe asked this question in Q&A
Discussion options

You must be logged in to vote

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),
	)
}

f…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Splizard
Comment options

@SteveMaybe
Comment options

Answer selected by Splizard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants