Repository: syncthing/syncthing
File: lib/model/service_map.go (Go)

Code before:
		s.eventLogger.Log(events.Failure, fmt.Sprintf("%s replaced service at key %v", s, k))
	}
	s.services[k] = v
	s.tokens[k] = s.supervisor.Add(v)
}

// Get returns the service at the given key, or the empty value and false if
// there is no service at that key.
func (s *serviceMap[K, S]) Get(k K) (v S, ok bool) {
	v, ok = s.services[k]
	return
}

// Stop removes the service from the supervisor, stopping it. The service itself
// is still retained, i.e. a call to Get with the same key will still return a
// result.
func (s *serviceMap[K, S]) Stop(k K) (found bool) {
	if tok, ok := s.tokens[k]; ok {
		found = true
		s.supervisor.Remove(tok)
	}
	delete(s.tokens, k)
	return
}

// RemoveAndWaitChan removes the service at the given key, stopping it on
// the supervisor. The returned channel will produce precisely one error
// value: either the return value from RemoveAndWait (possibly nil), or
// errSvcNotFound if the service was not found.
func (s *serviceMap[K, S]) StopAndWaitChan(k K, timeout time.Duration) <-chan error {
	ret := make(chan error, 1)
	if tok, ok := s.tokens[k]; ok {
		go func() {
			ret <- s.supervisor.RemoveAndWait(tok, timeout)
		}()
	} else {
		ret <- errSvcNotFound
	}
	delete(s.tokens, k)
	return ret
}

// Remove removes the service at the given key, stopping it on the supervisor.
// If there is no service at the given key, nothing happens. The return value
// indicates whether a service was removed.
func (s *serviceMap[K, S]) Remove(k K) (found bool) {
	if tok, ok := s.tokens[k]; ok {
		found = true
		s.supervisor.Remove(tok)
	} else {
		_, sok := s.services[k]

Review comment (suggestion):
```suggestion
// StopAndWaitChan removes the service at the given key, stopping it on
```

Code after:
		s.eventLogger.Log(events.Failure, fmt.Sprintf("%s replaced service at key %v", s, k))
	}
	s.services[k] = v
	s.tokens[k] = s.supervisor.Add(v)
}

// Get returns the service at the given key, or the empty value and false if
// there is no service at that key.
func (s *serviceMap[K, S]) Get(k K) (v S, ok bool) {
	v, ok = s.services[k]
	return
}

// Stop removes the service at the given key from the supervisor, stopping it.
// The service itself is still retained, i.e. a call to Get with the same key
// will still return a result.
func (s *serviceMap[K, S]) Stop(k K) {
	if tok, ok := s.tokens[k]; ok {
		s.supervisor.Remove(tok)
	}
	return
}

// StopAndWaitChan removes the service at the given key from the supervisor,
// stopping it. The service itself is still retained, i.e. a call to Get with
// the same key will still return a result.
// The returned channel will produce precisely one error value: either the
// return value from RemoveAndWait (possibly nil), or errSvcNotFound if the
// service was not found.
func (s *serviceMap[K, S]) StopAndWaitChan(k K, timeout time.Duration) <-chan error {
	ret := make(chan error, 1)
	if tok, ok := s.tokens[k]; ok {
		go func() {
			ret <- s.supervisor.RemoveAndWait(tok, timeout)
		}()
	} else {
		ret <- errSvcNotFound
	}
	return ret
}

// Remove removes the service at the given key, stopping it on the supervisor.
// If there is no service at the given key, nothing happens. The return value
// indicates whether a service was removed.
func (s *serviceMap[K, S]) Remove(k K) (found bool) {
	if tok, ok := s.tokens[k]; ok {
		found = true
		s.supervisor.Remove(tok)
	} else {
		_, found = s.services[k]
	}