Update manager.go

This commit is contained in:
songzhibin97 2024-03-02 18:49:31 +08:00
parent 0a2f33946b
commit e5827c9708

View file

@ -20,6 +20,7 @@ import (
"reflect"
"sort"
"sync"
"sync/atomic"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/event"
@ -58,6 +59,7 @@ type Manager struct {
quit chan chan error
term chan struct{} // Channel is closed upon termination of the update loop
close atomic.Bool // Whether the manager has been closed
lock sync.RWMutex
}
@ -98,6 +100,10 @@ func NewManager(config *Config, backends ...Backend) *Manager {
// Close terminates the account manager's internal notification processes.
func (am *Manager) Close() error {
if am.close.Swap(true) {
return nil
}
for _, w := range am.wallets {
w.Close()
}
@ -114,6 +120,10 @@ func (am *Manager) Config() *Config {
// AddBackend starts the tracking of an additional backend for wallet updates.
// cmd/geth assumes once this func returns the backends have been already integrated.
func (am *Manager) AddBackend(backend Backend) {
if am.close.Load() {
return
}
done := make(chan struct{})
am.newBackends <- newBackendEvent{backend, done}
<-done