Skip to content

Commit f30abdb

Browse files
authored
Merge pull request #72 from holden-cpu/main
pool support update address And pool close safe
2 parents b6769ea + 6eab374 commit f30abdb

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Diff for: addresspool/pool.go

+20-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ type Pool struct {
3535

3636
status map[string]string
3737
onceMonitor sync.Once
38+
quit chan struct{}
39+
onceQuit sync.Once
40+
}
41+
42+
func (p *Pool) Close() {
43+
p.onceQuit.Do(func() {
44+
close(p.quit)
45+
})
3846
}
3947

4048
// NewPool Get registry pool instance
@@ -57,6 +65,16 @@ func (p *Pool) appendAddressToStatus(addresses []string) {
5765
}
5866
}
5967

68+
func (p *Pool) ResetAddress(addresses []string) {
69+
p.mutex.Lock()
70+
defer p.mutex.Unlock()
71+
p.defaultAddress = removeDuplicates(addresses)
72+
p.diffAzAddress = []string{}
73+
p.sameAzAddress = []string{}
74+
p.status = make(map[string]string)
75+
p.appendAddressToStatus(addresses)
76+
}
77+
6078
func (p *Pool) SetAddressByInstances(instances []*discovery.MicroServiceInstance) error {
6179
p.mutex.Lock()
6280
defer p.mutex.Unlock()
@@ -179,14 +197,14 @@ func (p *Pool) monitor() {
179197
}
180198
}
181199
ticker := time.NewTicker(interval * time.Second)
182-
quit := make(chan struct{})
200+
p.quit = make(chan struct{})
183201

184202
go func() {
185203
for {
186204
select {
187205
case <-ticker.C:
188206
p.checkConnectivity()
189-
case <-quit:
207+
case <-p.quit:
190208
ticker.Stop()
191209
return
192210
}

0 commit comments

Comments
 (0)