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:
parent
7792dbc34d
commit
46d09ec2bc
@ -785,15 +785,21 @@ func (g *grpcServer) Deregister() error {
|
|||||||
|
|
||||||
g.registered = false
|
g.registered = false
|
||||||
|
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
for sb, subs := range g.subscribers {
|
for sb, subs := range g.subscribers {
|
||||||
for _, sub := range subs {
|
for _, sub := range subs {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(s broker.Subscriber) {
|
||||||
|
defer wg.Done()
|
||||||
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
if logger.V(logger.InfoLevel, logger.DefaultLogger) {
|
||||||
logger.Infof("Unsubscribing from topic: %s", sub.Topic())
|
logger.Infof("Unsubscribing from topic: %s", s.Topic())
|
||||||
}
|
}
|
||||||
sub.Unsubscribe()
|
s.Unsubscribe()
|
||||||
|
}(sub)
|
||||||
}
|
}
|
||||||
g.subscribers[sb] = nil
|
g.subscribers[sb] = nil
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
g.Unlock()
|
g.Unlock()
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user