From eac461041a982c2ec9e764218ce0b6254658978f Mon Sep 17 00:00:00 2001 From: Socket <30768657+Socketsj@users.noreply.github.com> Date: Thu, 30 Apr 2020 17:42:13 +0800 Subject: [PATCH] unsubscribe can async (#1596) Co-authored-by: huangshaojie Co-authored-by: Asim Aslam --- grpc.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/grpc.go b/grpc.go index 3de2332..a4501c0 100644 --- a/grpc.go +++ b/grpc.go @@ -785,15 +785,21 @@ func (g *grpcServer) Deregister() error { g.registered = false + wg := sync.WaitGroup{} for sb, subs := range g.subscribers { for _, sub := range subs { - if logger.V(logger.InfoLevel, logger.DefaultLogger) { - logger.Infof("Unsubscribing from topic: %s", sub.Topic()) - } - sub.Unsubscribe() + wg.Add(1) + go func(s broker.Subscriber) { + defer wg.Done() + if logger.V(logger.InfoLevel, logger.DefaultLogger) { + logger.Infof("Unsubscribing from topic: %s", s.Topic()) + } + s.Unsubscribe() + }(sub) } g.subscribers[sb] = nil } + wg.Wait() g.Unlock() return nil