mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-19 22:33:06 +00:00
fix: wg
This commit is contained in:
parent
9e1fce8457
commit
6c721f7ffd
@ -227,13 +227,15 @@ func (d *DiscoveryV5) Start() error {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
d.wg.Wait() // Waiting for other go routines to stop
|
||||
|
||||
d.quit = make(chan struct{}, 1)
|
||||
|
||||
err := d.listen()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
d.quit = make(chan struct{})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -241,11 +243,11 @@ func (d *DiscoveryV5) Stop() {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
close(d.quit)
|
||||
|
||||
d.listener.Close()
|
||||
d.listener = nil
|
||||
|
||||
close(d.quit)
|
||||
|
||||
log.Info("Stopped Discovery V5")
|
||||
|
||||
d.wg.Wait()
|
||||
@ -361,6 +363,8 @@ func (c *DiscoveryV5) Advertise(ctx context.Context, ns string, opts ...discover
|
||||
}
|
||||
|
||||
func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limit int, doneCh chan struct{}) {
|
||||
defer d.wg.Done()
|
||||
|
||||
for {
|
||||
if len(d.peerCache.recs) >= limit {
|
||||
break
|
||||
@ -393,7 +397,6 @@ func (d *DiscoveryV5) iterate(ctx context.Context, iterator enode.Iterator, limi
|
||||
}
|
||||
}
|
||||
|
||||
d.wg.Done()
|
||||
close(doneCh)
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user