Skip to content

Commit

Permalink
Hanndle When Channel Is Full
Browse files Browse the repository at this point in the history
Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
  • Loading branch information
rodneyosodo committed Jul 31, 2023
1 parent 970da5b commit b0e9f5a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion internal/clients/redis/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,22 @@ func (es *eventStore) Publish(ctx context.Context, event Event) error {
es.mu.Lock()
defer es.mu.Unlock()

es.unpublishedEvents <- record
select {
case es.unpublishedEvents <- record:
default:
// If the channel is full (rarely happens), drop the events.
return nil
}

return nil
}

return es.client.XAdd(ctx, record).Err()
}

func (es *eventStore) StartPublishingRoutine(ctx context.Context) {
defer close(es.unpublishedEvents)

ticker := time.NewTicker(unpublishedEventsCheckInterval)
defer ticker.Stop()

Expand Down

0 comments on commit b0e9f5a

Please sign in to comment.