long_poller_go/poller.go
insanity@loafle.com 448e2a97b9 long poller
2017-04-25 15:19:00 +09:00

42 lines
671 B
Go

package long_poller_go
import (
"fmt"
"loafle.com/overflow/cron_go"
"sync"
)
var (
POLLING_ID = "OVERFLOW_LONG_POLLING"
DEFAULT_INTERVAL = uint64(3)
)
type LongPoller struct {
once sync.Once
runStat chan bool
wg sync.WaitGroup
}
func (p *LongPoller) Start() {
p.once.Do(func() {
p.wg.Add(1)
p.startPolling()
p.wg.Wait()
})
}
func (p *LongPoller) startPolling() {
cr := &cron.Cron{}
p.runStat = cr.Start()
cr.AddTask(POLLING_ID, DEFAULT_INTERVAL).Invoke(p.poll, "agent0001")
}
func (p *LongPoller) Stop() {
p.runStat <- false
p.wg.Done()
}
func (p *LongPoller) poll(agentId string) {
fmt.Printf("%s :: LongPolling\n", agentId)
}