2 Star 2 Fork 7

王布衣 / gox

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
rolling_waitgroup.go 588 Bytes
一键复制 编辑 原始数据 按行查看 历史
package coroutine
import "sync"
// RollingWaitGroup 滑动窗口n的WaitGroup
type RollingWaitGroup struct {
window int
c chan struct{}
waitGroup sync.WaitGroup
}
// NewRollingWaitGroup initialization RollingWaitGroup struct
func NewRollingWaitGroup(n int) *RollingWaitGroup {
return &RollingWaitGroup{
window: n,
c: make(chan struct{}, n),
}
}
func (g *RollingWaitGroup) Add(delta int) {
g.c <- struct{}{}
g.waitGroup.Add(delta)
}
func (g *RollingWaitGroup) Done() {
g.waitGroup.Done()
<-g.c
}
func (g *RollingWaitGroup) Wait() {
g.waitGroup.Wait()
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/quant1x/gox.git
git@gitee.com:quant1x/gox.git
quant1x
gox
gox
v1.21.2

搜索帮助

344bd9b3 5694891 D2dac590 5694891