break loop when subscribe count is 0

This commit is contained in:
yaziming
2019-09-02 18:32:47 +08:00
parent 443d697c6f
commit 2b579cc642

View File

@@ -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 {