@@ -12,6 +12,8 @@ type NotificationProcessor interface {
12
12
// GetHandler returns the handler for a specific push notification name.
13
13
GetHandler (pushNotificationName string ) NotificationHandler
14
14
// ProcessPendingNotifications checks for and processes any pending push notifications.
15
+ // To be used when it is known that there are notifications on the socket.
16
+ // It will try to read from the socket and if it is empty - it may block.
15
17
ProcessPendingNotifications (ctx context.Context , handlerCtx NotificationHandlerContext , rd * proto.Reader ) error
16
18
// RegisterHandler registers a handler for a specific push notification name.
17
19
RegisterHandler (pushNotificationName string , handler NotificationHandler , protected bool ) error
@@ -47,6 +49,8 @@ func (p *Processor) UnregisterHandler(pushNotificationName string) error {
47
49
}
48
50
49
51
// ProcessPendingNotifications checks for and processes any pending push notifications
52
+ // This method should be called by the client in WithReader before reading the reply
53
+ // It will try to read from the socket and if it is empty - it may block.
50
54
func (p * Processor ) ProcessPendingNotifications (ctx context.Context , handlerCtx NotificationHandlerContext , rd * proto.Reader ) error {
51
55
if rd == nil {
52
56
return nil
@@ -134,6 +138,11 @@ func (v *VoidProcessor) UnregisterHandler(pushNotificationName string) error {
134
138
// ProcessPendingNotifications for VoidProcessor does nothing since push notifications
135
139
// are only available in RESP3 and this processor is used for RESP2 connections.
136
140
// This avoids unnecessary buffer scanning overhead.
141
+ // It does however read and discard all push notifications from the buffer to avoid
142
+ // them being interpreted as a reply.
143
+ // This method should be called by the client in WithReader before reading the reply
144
+ // to be sure there are no buffered push notifications.
145
+ // It will try to read from the socket and if it is empty - it may block.
137
146
func (v * VoidProcessor ) ProcessPendingNotifications (_ context.Context , handlerCtx NotificationHandlerContext , rd * proto.Reader ) error {
138
147
// read and discard all push notifications
139
148
if rd == nil {
0 commit comments