From 7fa1b92df4bf75cf53cbb3fa8b5d5cdae5414c7f Mon Sep 17 00:00:00 2001 From: Daniel Lohse Date: Sun, 7 Jan 2024 18:16:11 +0100 Subject: [PATCH] Improve implementation of the `EnableFallback` configuration option This goes back to the simple if and an early return when the option isn't enabled. --- pubsub/gochannel/pubsub.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pubsub/gochannel/pubsub.go b/pubsub/gochannel/pubsub.go index b243d31e0..fb9bf9f42 100644 --- a/pubsub/gochannel/pubsub.go +++ b/pubsub/gochannel/pubsub.go @@ -148,15 +148,15 @@ func (g *GoChannel) sendMessage(topic string, message *message.Message) (<-chan logFields := watermill.LogFields{"message_uuid": message.UUID, "topic": topic} - switch { - case len(subscribers) == 0 && g.config.EnableFallback: + if len(subscribers) == 0 { + if !g.config.EnableFallback { + return g.handleNoSubscribers(ackedBySubscribers, logFields) + } + g.logger.Debug("No subscribers to send the message to, trying the fallback subscribers", logFields) - subscribers = g.topicSubscribers(NoSubscribersFallbackTopic) - if len(subscribers) == 0 { + if subscribers = g.topicSubscribers(NoSubscribersFallbackTopic); len(subscribers) == 0 { return g.handleNoSubscribers(ackedBySubscribers, logFields) } - case len(subscribers) == 0: - return g.handleNoSubscribers(ackedBySubscribers, logFields) } go func(subscribers []*subscriber) {