@@ -209,7 +209,7 @@ type baseClient struct {
209
209
onClose func () error // hook called when client is closed
210
210
211
211
// Push notification processing
212
- pushProcessor * PushNotificationProcessor
212
+ pushProcessor PushNotificationProcessorInterface
213
213
}
214
214
215
215
func (c * baseClient ) clone () * baseClient {
@@ -535,7 +535,7 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool
535
535
}
536
536
if err := cn .WithReader (c .context (ctx ), c .cmdTimeout (cmd ), func (rd * proto.Reader ) error {
537
537
// Check for push notifications before reading the command reply
538
- if c .opt .Protocol == 3 && c .pushProcessor != nil && c . pushProcessor .IsEnabled () {
538
+ if c .opt .Protocol == 3 && c .pushProcessor .IsEnabled () {
539
539
if err := c .pushProcessor .ProcessPendingNotifications (ctx , rd ); err != nil {
540
540
internal .Logger .Printf (ctx , "push: error processing push notifications: %v" , err )
541
541
}
@@ -772,9 +772,7 @@ func NewClient(opt *Options) *Client {
772
772
c .initializePushProcessor ()
773
773
774
774
// Update options with the initialized push processor for connection pool
775
- if c .pushProcessor != nil {
776
- opt .PushNotificationProcessor = c .pushProcessor
777
- }
775
+ opt .PushNotificationProcessor = c .pushProcessor
778
776
779
777
c .connPool = newConnPool (opt , c .dialHook )
780
778
@@ -819,23 +817,23 @@ func (c *Client) initializePushProcessor() {
819
817
if c .opt .PushNotificationProcessor != nil {
820
818
c .pushProcessor = c .opt .PushNotificationProcessor
821
819
} else if c .opt .PushNotifications {
822
- // Create default processor only if push notifications are enabled
820
+ // Create default processor when push notifications are enabled
823
821
c .pushProcessor = NewPushNotificationProcessor (true )
822
+ } else {
823
+ // Create void processor when push notifications are disabled
824
+ c .pushProcessor = NewVoidPushNotificationProcessor ()
824
825
}
825
826
}
826
827
827
828
// RegisterPushNotificationHandler registers a handler for a specific push notification name.
828
829
// Returns an error if a handler is already registered for this push notification name.
829
830
// If protected is true, the handler cannot be unregistered.
830
831
func (c * Client ) RegisterPushNotificationHandler (pushNotificationName string , handler PushNotificationHandler , protected bool ) error {
831
- if c .pushProcessor != nil {
832
- return c .pushProcessor .RegisterHandler (pushNotificationName , handler , protected )
833
- }
834
- return nil
832
+ return c .pushProcessor .RegisterHandler (pushNotificationName , handler , protected )
835
833
}
836
834
837
835
// GetPushNotificationProcessor returns the push notification processor.
838
- func (c * Client ) GetPushNotificationProcessor () * PushNotificationProcessor {
836
+ func (c * Client ) GetPushNotificationProcessor () PushNotificationProcessorInterface {
839
837
return c .pushProcessor
840
838
}
841
839
@@ -886,10 +884,8 @@ func (c *Client) pubSub() *PubSub {
886
884
}
887
885
pubsub .init ()
888
886
889
- // Set the push notification processor if available
890
- if c .pushProcessor != nil {
891
- pubsub .SetPushNotificationProcessor (c .pushProcessor )
892
- }
887
+ // Set the push notification processor
888
+ pubsub .SetPushNotificationProcessor (c .pushProcessor )
893
889
894
890
return pubsub
895
891
}
@@ -974,10 +970,8 @@ func newConn(opt *Options, connPool pool.Pooler, parentHooks *hooksMixin) *Conn
974
970
c .hooksMixin = parentHooks .clone ()
975
971
}
976
972
977
- // Set push notification processor if available in options
978
- if opt .PushNotificationProcessor != nil {
979
- c .pushProcessor = opt .PushNotificationProcessor
980
- }
973
+ // Set push notification processor from options (always available now)
974
+ c .pushProcessor = opt .PushNotificationProcessor
981
975
982
976
c .cmdable = c .Process
983
977
c .statefulCmdable = c .Process
@@ -1001,14 +995,11 @@ func (c *Conn) Process(ctx context.Context, cmd Cmder) error {
1001
995
// Returns an error if a handler is already registered for this push notification name.
1002
996
// If protected is true, the handler cannot be unregistered.
1003
997
func (c * Conn ) RegisterPushNotificationHandler (pushNotificationName string , handler PushNotificationHandler , protected bool ) error {
1004
- if c .pushProcessor != nil {
1005
- return c .pushProcessor .RegisterHandler (pushNotificationName , handler , protected )
1006
- }
1007
- return nil
998
+ return c .pushProcessor .RegisterHandler (pushNotificationName , handler , protected )
1008
999
}
1009
1000
1010
1001
// GetPushNotificationProcessor returns the push notification processor.
1011
- func (c * Conn ) GetPushNotificationProcessor () * PushNotificationProcessor {
1002
+ func (c * Conn ) GetPushNotificationProcessor () PushNotificationProcessorInterface {
1012
1003
return c .pushProcessor
1013
1004
}
1014
1005
0 commit comments