Skip to content

Commit

Permalink
fix!
Browse files Browse the repository at this point in the history
  • Loading branch information
Raezil committed Dec 7, 2024
1 parent 80dc5ed commit ee48ad5
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions eventstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ func NewEventStore(dispatcher *Dispatcher) *EventStore {

// Publish adds an event to the event pool
func (eventstore *EventStore) Publish(event *Event) {
if event == nil {
log.Println("Attempted to publish a nil event")
return
}
eventstore.Events.Put(event)
}

Expand Down Expand Up @@ -63,7 +59,8 @@ func (eventstore *EventStore) Commit() error {
return fmt.Errorf("error handling event: %w", err)
}

log.Printf("Event id: %s was successfully processed", event.Id)
log.Printf("Event id: %s was successfully published", event.Id)

return nil
}

Expand All @@ -73,15 +70,18 @@ func (eventstore *EventStore) Broadcast() error {
defer eventstore.Mutex.Unlock()

var lastErr error
// Try to commit an event
for {
err := eventstore.Commit()
if err != nil {
if err.Error() == "no events to process" {
// If there are no more events to process, break the loop
if err.Error() != "" {
break
}
// Capture the last error if something else goes wrong
lastErr = err
log.Printf("Error processing event: %v", err)
}

}

return lastErr
Expand Down

0 comments on commit ee48ad5

Please sign in to comment.