atomic close 2 channels (#3498)

This commit is contained in:
Alex Sharov 2022-02-13 00:09:17 +07:00 committed by GitHub
parent 2074b98568
commit 1ba95c1087
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -121,6 +121,8 @@ func (pi *PeerInfo) ClearDeadlines(now time.Time, givePermit bool) int {
}
func (pi *PeerInfo) Remove() {
pi.lock.Lock()
defer pi.lock.Unlock()
pi.removeOnce.Do(func() {
close(pi.removed)
close(pi.tasks)
@ -128,6 +130,8 @@ func (pi *PeerInfo) Remove() {
}
func (pi *PeerInfo) Async(f func()) {
pi.lock.Lock()
defer pi.lock.Unlock()
select {
case <-pi.removed: // noop if peer removed
case pi.tasks <- f: