From 5491244d01621d1012285d00cb20d2144cc0e2ca Mon Sep 17 00:00:00 2001 From: ycc Date: Tue, 23 Apr 2024 22:48:37 +0200 Subject: [PATCH] Refactor RedisRouter subscribe function to include timeout parameter --- server/router.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/router.go b/server/router.go index b068da4..8be5ce3 100644 --- a/server/router.go +++ b/server/router.go @@ -59,7 +59,7 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe } if msg.Timeout > 0 { // set timeout for the lookup - r.subscribe(msg) + r.subscribe(msg, int(msg.Timeout)) } } // manage Matriochka @@ -196,7 +196,7 @@ func goSubscribeAndListen(client *redis.Client, key string, messages chan<- stri } } -func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage) (*meowlib.FromServerMessage, error) { +func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage, timeout int) (*meowlib.FromServerMessage, error) { var from_server meowlib.FromServerMessage // update messages counter err := r.Client.Incr("statistics:messages:messagessubscription").Err() @@ -217,7 +217,7 @@ func (r *RedisRouter) subscribe(msg *meowlib.ToServerMessage) (*meowlib.FromServ case <-messages: close(done) return r.checkForMessage(msg) - case <-time.After(10 * time.Second): // 10 seconds timeout + case <-time.After(time.Duration(timeout) * time.Second): // 10 seconds timeout close(done) } wg.Wait()