Skip to content

Commit

Permalink
chore: log global properties
Browse files Browse the repository at this point in the history
  • Loading branch information
rolznz committed Aug 2, 2024
1 parent 390a02a commit abec373
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@ func NewEventPublisher() *eventPublisher {
return eventPublisher
}

func (el *eventPublisher) RegisterSubscriber(listener EventSubscriber) {
el.subscriberMtx.Lock()
defer el.subscriberMtx.Unlock()
el.listeners = append(el.listeners, listener)
func (ep *eventPublisher) RegisterSubscriber(listener EventSubscriber) {
ep.subscriberMtx.Lock()
defer ep.subscriberMtx.Unlock()
ep.listeners = append(ep.listeners, listener)
}

func (el *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) {
el.subscriberMtx.Lock()
defer el.subscriberMtx.Unlock()
func (ep *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) {
ep.subscriberMtx.Lock()
defer ep.subscriberMtx.Unlock()

for i, listener := range el.listeners {
for i, listener := range ep.listeners {
// delete the listener from the listeners array
if listener == listenerToRemove {
el.listeners[i] = el.listeners[len(el.listeners)-1]
el.listeners = slices.Delete(el.listeners, len(el.listeners)-1, len(el.listeners))
ep.listeners[i] = ep.listeners[len(ep.listeners)-1]
ep.listeners = slices.Delete(ep.listeners, len(ep.listeners)-1, len(ep.listeners))
break
}
}
Expand All @@ -46,14 +46,14 @@ func (el *eventPublisher) RemoveSubscriber(listenerToRemove EventSubscriber) {
func (ep *eventPublisher) Publish(event *Event) {
ep.subscriberMtx.Lock()
defer ep.subscriberMtx.Unlock()
logger.Logger.WithFields(logrus.Fields{"event": event}).Info("Publishing event")
logger.Logger.WithFields(logrus.Fields{"event": event, "global": ep.globalProperties}).Info("Publishing event")
for _, listener := range ep.listeners {
// events are consumed in sequence as some listeners depend on earlier consumers
// (e.g. NIP-47 notifier depends on transactions service updating transactions)
listener.ConsumeEvent(context.Background(), event, ep.globalProperties)
}
}

func (el *eventPublisher) SetGlobalProperty(key string, value interface{}) {
el.globalProperties[key] = value
func (ep *eventPublisher) SetGlobalProperty(key string, value interface{}) {
ep.globalProperties[key] = value
}

0 comments on commit abec373

Please sign in to comment.