Skip to content

Commit

Permalink
fix: minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Selivanov committed Jun 26, 2023
1 parent 4ea7d5b commit 2012202
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions services_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ func (p *ServicesPool) DiscoverServices() error {
continue
}

isServiceExists := p.list.IsServiceExists(newService)
var mutatedService service.IService

// if service doesn't exist in pool or if the callback returns true --
// then we do a mutation.
// otherwise we prefer not to mutate srv to prevent spawning unnecessary goroutines
if !isServiceExists || p.mutationNeededCallback(newService) {
isServiceExists := p.list.IsServiceExists(newService)
weNeedToMutate := !isServiceExists || (p.mutationNeededCallback != nil && p.mutationNeededCallback(newService))
var mutatedService service.IService

if weNeedToMutate {
mutatedService, err = p.MutationFnc(newService)
if err != nil {
logger.Log().Warn(fmt.Sprintf("mutate new discovered service: %s", err))
Expand All @@ -190,7 +191,6 @@ func (p *ServicesPool) DiscoverServices() error {
if isServiceExists {
continue
}

p.list.Add(mutatedService)
}
return nil
Expand Down

0 comments on commit 2012202

Please sign in to comment.