重命名客户端相关术语为节点;移动 utils 包到根路径;优化网关对节点各种连接状态的处理,并在节点断联后统一清理资源

This commit is contained in:
2025-05-17 10:00:28 +08:00
parent 20ac7dbd91
commit 84e01d3b50
14 changed files with 150 additions and 129 deletions

44
utils/sync.go Normal file
View File

@@ -0,0 +1,44 @@
package utils
import (
"sync"
"sync/atomic"
)
type WaitGroup interface {
Add(delta int)
Done()
Wait()
}
type CountWaitGroup struct {
wg sync.WaitGroup
num atomic.Int64
}
func (c *CountWaitGroup) Add(delta int) {
c.wg.Add(delta)
c.num.Add(int64(delta))
}
func (c *CountWaitGroup) Done() {
c.wg.Done()
c.num.Add(-1)
}
func (c *CountWaitGroup) Wait() {
c.wg.Wait()
}
func (c *CountWaitGroup) Count() uint64 {
return uint64(c.num.Load())
}
func WgWait[T WaitGroup](wg T) <-chan struct{} {
ch := make(chan struct{})
go func() {
wg.Wait()
ch <- struct{}{}
}()
return ch
}