1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-24 10:07:04 +02:00

unsubscribe can async (#1596)

Co-authored-by: huangshaojie <huangshaojie@corp.netease.com>
Co-authored-by: Asim Aslam <asim@aslam.me>
This commit is contained in:
Socket 2020-04-30 17:42:13 +08:00 committed by GitHub
parent 7792dbc34d
commit 46d09ec2bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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