Skip to content

Commit 1c25186

Browse files
author
willzhen
committed
Migrate code
1 parent 050ba34 commit 1c25186

File tree

5 files changed

+1019
-0
lines changed

5 files changed

+1019
-0
lines changed

Diff for: go.mod

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module github.com/memory-overflow/go-orderedmap
2+
3+
go 1.16
4+
5+
require (
6+
github.com/json-iterator/go v1.1.12
7+
)

Diff for: limit_waitgroup.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package stlextension
2+
3+
import "sync"
4+
5+
// LimitWaitGroup ...
6+
type LimitWaitGroup struct {
7+
wg sync.WaitGroup
8+
bucket chan struct{}
9+
}
10+
11+
// NewLimitWaitGroup ...
12+
func NewLimitWaitGroup(limit uint) *LimitWaitGroup {
13+
return &LimitWaitGroup{
14+
wg: sync.WaitGroup{},
15+
bucket: make(chan struct{}, limit),
16+
}
17+
}
18+
19+
// Add ...
20+
func (w *LimitWaitGroup) Add(delta int) {
21+
w.wg.Add(delta)
22+
for i := 0; i < delta; i++ {
23+
w.bucket <- struct{}{}
24+
}
25+
}
26+
27+
// Done ...
28+
func (w *LimitWaitGroup) Done() {
29+
<-w.bucket
30+
w.wg.Done()
31+
}
32+
33+
// Wait ...
34+
func (w *LimitWaitGroup) Wait() {
35+
w.wg.Wait()
36+
}

0 commit comments

Comments
 (0)