Close stops this failure watcher and closes channel returned by Chan() method. After closing failure watcher, it cannot be used to watch additional services or managers. Repeated calls to Close() do nothing.
()
| 78 | // it cannot be used to watch additional services or managers. |
| 79 | // Repeated calls to Close() do nothing. |
| 80 | func (w *FailureWatcher) Close() { |
| 81 | // Graceful handle the case FailureWatcher has not been initialized, |
| 82 | // to simplify the code in the components using it. |
| 83 | if w == nil { |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | w.mu.Lock() |
| 88 | defer w.mu.Unlock() |
| 89 | |
| 90 | if w.closed { |
| 91 | return |
| 92 | } |
| 93 | for _, stop := range w.unregisterListeners { |
| 94 | stop() |
| 95 | } |
| 96 | |
| 97 | // All listeners are now stopped, and can't receive more notifications. We can close the channel. |
| 98 | close(w.ch) |
| 99 | w.closed = true |
| 100 | } |
no outgoing calls