Skip to content

Commit f132d4a

Browse files
gofmt
Signed-off-by: Said Altury <Said.Altury@ibm.com>
1 parent 868ff85 commit f132d4a

File tree

2 files changed

+249
-252
lines changed

2 files changed

+249
-252
lines changed

platform/fabricx/core/finality/nlm.go

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -166,46 +166,46 @@ func (n *notificationListenerManager) AddFinalityListener(txID driver.TxID, list
166166
}
167167

168168
func (n *notificationListenerManager) RemoveFinalityListener(txID string, listener fabric.FinalityListener) error {
169-
if listener == nil {
170-
return errors.New("listener nil")
171-
}
172-
173-
n.lock.Lock()
174-
defer n.lock.Unlock()
175-
176-
handlers, ok := n.handlers[txID]
177-
if !ok || len(handlers) == 0 {
178-
// No handlers registered for this txID, nothing to remove
179-
logger.Debugf("RemoveFinalityListener called for unknown txID: %s", txID)
180-
return nil
181-
}
182-
183-
// Find and remove the specific listener by creating a new slice
184-
newHandlers := make([]fabric.FinalityListener, 0, len(handlers))
185-
removed := false
186-
for _, h := range handlers {
187-
if h == listener {
188-
removed = true
189-
} else {
190-
newHandlers = append(newHandlers, h)
191-
}
192-
}
193-
194-
if !removed {
195-
logger.Warnf("Listener not found for txID=%s, cannot remove. This might be a logic error.", txID)
196-
return nil
197-
}
198-
199-
n.handlers[txID] = newHandlers
200-
201-
// Check if the list of handlers is now empty
202-
if len(newHandlers) == 0 {
203-
// This was the last listener. We only need to clean up our local map entry.
204-
logger.Debugf("Last finality listener removed for txID=%s.", txID)
205-
delete(n.handlers, txID)
206-
} else {
207-
logger.Debugf("Removed listener for txID=%s. %d listeners remaining.", txID, len(newHandlers))
208-
}
209-
210-
return nil
211-
}
169+
if listener == nil {
170+
return errors.New("listener nil")
171+
}
172+
173+
n.lock.Lock()
174+
defer n.lock.Unlock()
175+
176+
handlers, ok := n.handlers[txID]
177+
if !ok || len(handlers) == 0 {
178+
// No handlers registered for this txID, nothing to remove
179+
logger.Debugf("RemoveFinalityListener called for unknown txID: %s", txID)
180+
return nil
181+
}
182+
183+
// Find and remove the specific listener by creating a new slice
184+
newHandlers := make([]fabric.FinalityListener, 0, len(handlers))
185+
removed := false
186+
for _, h := range handlers {
187+
if h == listener {
188+
removed = true
189+
} else {
190+
newHandlers = append(newHandlers, h)
191+
}
192+
}
193+
194+
if !removed {
195+
logger.Warnf("Listener not found for txID=%s, cannot remove. This might be a logic error.", txID)
196+
return nil
197+
}
198+
199+
n.handlers[txID] = newHandlers
200+
201+
// Check if the list of handlers is now empty
202+
if len(newHandlers) == 0 {
203+
// This was the last listener. We only need to clean up our local map entry.
204+
logger.Debugf("Last finality listener removed for txID=%s.", txID)
205+
delete(n.handlers, txID)
206+
} else {
207+
logger.Debugf("Removed listener for txID=%s. %d listeners remaining.", txID, len(newHandlers))
208+
}
209+
210+
return nil
211+
}

0 commit comments

Comments
 (0)