From bf087ba004881694a1449958adb7be84d92363fe Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Thu, 17 Mar 2022 09:15:09 -0700 Subject: [PATCH] feat: add RequestContext to PubSubConn (TBD) Add a wrapper that goes through the standard receiveInternal processing to match the API of the existing PubSubConn Receive methods. Fixes: #592 --- redis/pubsub.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/redis/pubsub.go b/redis/pubsub.go index cc585757..f2f721af 100644 --- a/redis/pubsub.go +++ b/redis/pubsub.go @@ -15,6 +15,7 @@ package redis import ( + "context" "errors" "time" ) @@ -116,6 +117,12 @@ func (c PubSubConn) ReceiveWithTimeout(timeout time.Duration) interface{} { return c.receiveInternal(ReceiveWithTimeout(c.Conn, timeout)) } +// ReceiveContext is like Receive, but it allows termination of the receive +// via a Context. +func (c PubSubConn) ReceiveContext(ctx context.Context) interface{} { + return c.receiveInternal(ReceiveContext(c.Conn, ctx)) +} + func (c PubSubConn) receiveInternal(replyArg interface{}, errArg error) interface{} { reply, err := Values(replyArg, errArg) if err != nil {