定时器对象 不使用的时候释放掉

This commit is contained in:
meixiongfeng 2022-08-25 11:32:33 +08:00
parent 88423a2301
commit 564204c777
2 changed files with 4 additions and 2 deletions

View File

@ -55,6 +55,7 @@ func (c *ConnServiceImpl) WsConnect(wsUrl string) error {
c.ws = ws
ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
go func() {
for {
_ = <-ticker.C

View File

@ -46,14 +46,15 @@ type Configure struct {
}
func (this *Configure) Start() (err error) {
tc := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
timer := time.NewTicker(time.Second * time.Duration(this.options.CheckInterval))
defer timer.Stop()
go func() {
locp:
for {
select {
case <-this.closeSignal:
break locp
case <-tc.C:
case <-timer.C:
this.checkConfigure()
}
}