Schedule is used to ensure the Tick is performed periodically. This function is safe to call multiple times. If the memberlist is already scheduled, then it won't do anything.
()
| 120 | // function is safe to call multiple times. If the memberlist is already |
| 121 | // scheduled, then it won't do anything. |
| 122 | func (m *Memberlist) schedule() { |
| 123 | m.tickerLock.Lock() |
| 124 | defer m.tickerLock.Unlock() |
| 125 | |
| 126 | // If we already have tickers, then don't do anything, since we're |
| 127 | // scheduled |
| 128 | if len(m.tickers) > 0 { |
| 129 | return |
| 130 | } |
| 131 | |
| 132 | // Create the stop tick channel, a blocking channel. We close this |
| 133 | // when we should stop the tickers. |
| 134 | stopCh := make(chan struct{}) |
| 135 | |
| 136 | // Create a new probeTicker |
| 137 | if m.config.ProbeInterval > 0 { |
| 138 | t := time.NewTicker(m.config.ProbeInterval) |
| 139 | go m.triggerFunc(m.config.ProbeInterval, t.C, stopCh, m.probe) |
| 140 | m.tickers = append(m.tickers, t) |
| 141 | } |
| 142 | |
| 143 | // Create a push pull ticker if needed |
| 144 | if m.config.PushPullInterval > 0 { |
| 145 | go m.pushPullTrigger(stopCh) |
| 146 | } |
| 147 | |
| 148 | // Create a gossip ticker if needed |
| 149 | if m.config.GossipInterval > 0 && m.config.GossipNodes > 0 { |
| 150 | t := time.NewTicker(m.config.GossipInterval) |
| 151 | go m.triggerFunc(m.config.GossipInterval, t.C, stopCh, m.gossip) |
| 152 | m.tickers = append(m.tickers, t) |
| 153 | } |
| 154 | |
| 155 | // If we made any tickers, then record the stopTick channel for |
| 156 | // later. |
| 157 | if len(m.tickers) > 0 { |
| 158 | m.stopTick = stopCh |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | // triggerFunc is used to trigger a function call each time a |
| 163 | // message is received until a stop tick arrives. |