code: func (r *RegisterMonitor) Close() error {
  	r.lock.Lock()
  	defer r.lock.Unlock()
  
  	for {
  		switch r.runState {
  		case registerStateIdle:
  			// Idle so just set it to stopped and return. We notify
  			// the condition variable in case others are waiting.
  			r.runState = registerStateStopped
  			r.cond.Broadcast()
  			return nil
  
  		case registerStateRunning:
  			// Set the state to stopping and broadcast to all waiters,
  			// since Run is sitting on cond.Wait.
  			r.runState = registerStateStopping
  			r.cond.Broadcast()
  			r.cond.Wait() // Wait on the stopping event
  
  		case registerStateStopping:
  			// Still stopping, wait...
  			r.cond.Wait()
  
  		case registerStateStopped:
  			// Stopped, target state reached
  			return nil
  		}
  	}
  }
docs: // Close stops the register goroutines and deregisters the service. Once
  // Close is called, the monitor can no longer be used again. It is safe to
  // call Close multiple times and concurrently.