I have defined few tickers and when I try to stop them, I see below
undefined: ticker in ticker.Stop
undefined: Q30sticker in Q30sticker.Stop
Code sample:
if activenode() {
cipaflage = true
break
} else {
if cipaflage == true {
defer ticker.Stop()
defer Q30sticker.Stop()
cipaflage = false
}
continue
}
And I have declared the ticker as below
ticker := time.NewTicker(59 * time.Second)
Q30sticker := time.NewTicker(time.Second * 30).C
As per the docs here
Ticker
has an exported field C
.
type Ticker struct {
C <-chan Time // The channel on which the ticks are delivered.
// contains filtered or unexported fields
}
You can receive the "ticks", or heartbeats on the C
channel, but if you are doing this:
Q30sticker := time.NewTicker(time.Second * 30).C
then Q30sticker
holds a reference to the channel C
and not the ticker type. It is the time.Ticker
struct that defines the Stop
method.
Update your variable to hold the ticker type (by removing .C
):
Q30sticker := time.NewTicker(time.Second * 30)
And where you receive from the channel, use the .
dot syntax to access the channel.
<-Q30sticker.C