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

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 c.ws = ws
ticker := time.NewTicker(2 * time.Second) ticker := time.NewTicker(2 * time.Second)
defer ticker.Stop()
go func() { go func() {
for { for {
_ = <-ticker.C _ = <-ticker.C

View File

@ -46,14 +46,15 @@ type Configure struct {
} }
func (this *Configure) Start() (err error) { 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() { go func() {
locp: locp:
for { for {
select { select {
case <-this.closeSignal: case <-this.closeSignal:
break locp break locp
case <-tc.C: case <-timer.C:
this.checkConfigure() this.checkConfigure()
} }
} }