From 300560b44451bd9d5241ccdbaea3576760968ef2 Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Wed, 18 Aug 2021 00:27:08 +0300 Subject: Update broadcast tests, improve stop mechanism. Signed-off-by: Valery Piashchynski --- plugins/redis/pubsub/pubsub.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'plugins/redis/pubsub/pubsub.go') diff --git a/plugins/redis/pubsub/pubsub.go b/plugins/redis/pubsub/pubsub.go index 95a9f6dd..c9ad3d58 100644 --- a/plugins/redis/pubsub/pubsub.go +++ b/plugins/redis/pubsub/pubsub.go @@ -172,6 +172,12 @@ func (p *PubSubDriver) Connections(topic string, res map[string]struct{}) { } // Next return next message -func (p *PubSubDriver) Next() (*pubsub.Message, error) { - return p.channel.message(), nil +func (p *PubSubDriver) Next(ctx context.Context) (*pubsub.Message, error) { + const op = errors.Op("redis_driver_next") + select { + case msg := <-p.channel.message(): + return msg, nil + case <-ctx.Done(): + return nil, errors.E(op, errors.TimeOut, ctx.Err()) + } } -- cgit v1.2.3