| 35 | } |
| 36 | |
| 37 | func (w *FailureWatcher) WatchService(service Service) { |
| 38 | // Ensure that if the caller request to watch a service, then the FailureWatcher |
| 39 | // has been initialized. |
| 40 | if w == nil { |
| 41 | panic(errFailureWatcherNotInitialized) |
| 42 | } |
| 43 | |
| 44 | w.mu.Lock() |
| 45 | defer w.mu.Unlock() |
| 46 | |
| 47 | if w.closed { |
| 48 | panic(errFailureWatcherClosed) |
| 49 | } |
| 50 | |
| 51 | stop := service.AddListener(NewListener(nil, nil, nil, nil, func(_ State, failure error) { |
| 52 | w.ch <- errors.Wrapf(failure, "service %s failed", DescribeService(service)) |
| 53 | })) |
| 54 | w.unregisterListeners = append(w.unregisterListeners, stop) |
| 55 | } |
| 56 | |
| 57 | func (w *FailureWatcher) WatchManager(manager *Manager) { |
| 58 | // Ensure that if the caller request to watch services, then the FailureWatcher |