From 201220208bfef620a257099c38c10d14f4088a8c Mon Sep 17 00:00:00 2001 From: Dmitry Selivanov Date: Mon, 26 Jun 2023 13:09:49 +0200 Subject: [PATCH] fix: minor refactor --- services_pool.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/services_pool.go b/services_pool.go index b3c028a..cf8de85 100644 --- a/services_pool.go +++ b/services_pool.go @@ -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)) @@ -190,7 +191,6 @@ func (p *ServicesPool) DiscoverServices() error { if isServiceExists { continue } - p.list.Add(mutatedService) } return nil