From 2b579cc64263b96ff15b8bcbf14cd585ca18caca Mon Sep 17 00:00:00 2001 From: yaziming Date: Mon, 2 Sep 2019 18:32:47 +0800 Subject: [PATCH] break loop when subscribe count is 0 --- backend/database/pubsub.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/database/pubsub.go b/backend/database/pubsub.go index 152dc9a3..c5fdbda9 100644 --- a/backend/database/pubsub.go +++ b/backend/database/pubsub.go @@ -40,11 +40,11 @@ func (r *Redis) subscribe(ctx context.Context, consume ConsumeFunc, channel ...s } case redis.Subscription: fmt.Println(msg) - // - //if msg.Count == 0 { - // // all channels are unsubscribed - // return - //} + + if msg.Count == 0 { + // all channels are unsubscribed + return + } } } @@ -54,9 +54,9 @@ func (r *Redis) subscribe(ctx context.Context, consume ConsumeFunc, channel ...s select { case <-ctx.Done(): if err := psc.Unsubscribe(); err != nil { - fmt.Printf("redis pubsub unsubscribe err: %v", err) + fmt.Printf("redis pubsub unsubscribe err: %v \n", err) } - return nil + done <- nil case <-tick.C: //fmt.Printf("ping message \n") if err := psc.Ping(""); err != nil {