mirror of
https://github.com/libp2p/go-libp2p-peerstore.git
synced 2025-01-01 00:20:11 +08:00
Remove redundant channel from ttlmanager
This commit is contained in:
parent
785b890ecb
commit
7e3363eeb4
@ -34,7 +34,7 @@ func NewDatastoreAddrManager(ctx context.Context, ds ds.Batching, ttlInterval ti
|
|||||||
|
|
||||||
// Stop will signal the TTL manager to stop and block until it returns.
|
// Stop will signal the TTL manager to stop and block until it returns.
|
||||||
func (mgr *DatastoreAddrManager) Stop() {
|
func (mgr *DatastoreAddrManager) Stop() {
|
||||||
mgr.ttlManager.stop()
|
mgr.ttlManager.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
func peerAddressKey(p *peer.ID, addr *ma.Multiaddr) (ds.Key, error) {
|
func peerAddressKey(p *peer.ID, addr *ma.Multiaddr) (ds.Key, error) {
|
||||||
@ -210,7 +210,6 @@ type ttlmanager struct {
|
|||||||
ctx context.Context
|
ctx context.Context
|
||||||
cancel context.CancelFunc
|
cancel context.CancelFunc
|
||||||
ticker *time.Ticker
|
ticker *time.Ticker
|
||||||
done chan struct{}
|
|
||||||
ds ds.Datastore
|
ds ds.Datastore
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +221,6 @@ func newTTLManager(parent context.Context, d ds.Datastore, tick time.Duration) *
|
|||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
ticker: time.NewTicker(tick),
|
ticker: time.NewTicker(tick),
|
||||||
ds: d,
|
ds: d,
|
||||||
done: make(chan struct{}),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
@ -230,7 +228,6 @@ func newTTLManager(parent context.Context, d ds.Datastore, tick time.Duration) *
|
|||||||
select {
|
select {
|
||||||
case <-mgr.ctx.Done():
|
case <-mgr.ctx.Done():
|
||||||
mgr.ticker.Stop()
|
mgr.ticker.Stop()
|
||||||
mgr.done <- struct{}{}
|
|
||||||
return
|
return
|
||||||
case <-mgr.ticker.C:
|
case <-mgr.ticker.C:
|
||||||
mgr.tick()
|
mgr.tick()
|
||||||
@ -241,11 +238,6 @@ func newTTLManager(parent context.Context, d ds.Datastore, tick time.Duration) *
|
|||||||
return mgr
|
return mgr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mgr *ttlmanager) stop() {
|
|
||||||
mgr.cancel()
|
|
||||||
<-mgr.done
|
|
||||||
}
|
|
||||||
|
|
||||||
// To be called by TTL manager's coroutine only.
|
// To be called by TTL manager's coroutine only.
|
||||||
func (mgr *ttlmanager) tick() {
|
func (mgr *ttlmanager) tick() {
|
||||||
mgr.RLock()
|
mgr.RLock()
|
||||||
|
Loading…
Reference in New Issue
Block a user