code: func maxIndexAndWatchChForService(tx *memdb.Txn, serviceName string, serviceExists, checks bool) (uint64, <-chan struct{}) {
  	if !serviceExists {
  		res, err := tx.First("index", "id", serviceLastExtinctionIndexName)
  		if missingIdx, ok := res.(*IndexEntry); ok && err == nil {
  			// Not safe to only watch the extinction index as it's not updated when
  			// new instances come along so return nil watchCh.
  			return missingIdx.Value, nil
  		}
  	}
  
  	ch, res, err := tx.FirstWatch("index", "id", serviceIndexName(serviceName))
  	if idx, ok := res.(*IndexEntry); ok && err == nil {
  		return idx.Value, ch
  	}
  	if checks {
  		return maxIndexTxn(tx, "nodes", "services", "checks"), nil
  	}
  
  	return maxIndexTxn(tx, "nodes", "services"), nil
  }
docs: // maxIndexAndWatchChForService return the maximum Raft Index for a service. If
  // the index is not set for the service, it will return the missing service
  // index. The service_last_extinction is set to the last raft index when a
  // service was unregistered (or 0 if no services were ever unregistered). This
  // allows blocking queries to
  //   * return when the last instance of a service is removed
  //   * block until an instance for this service is available, or another
  //     service is unregistered.
  //
  // It also _may_ return a watch chan to add to a WatchSet. It will only return
  // one if the service exists, and has a service index. If it doesn't then nil is
  // returned for the chan. This allows for blocking watchers to _only_ watch this
  // one chan in the common case, falling back to watching all touched MemDB
  // indexes in more complicated cases.