blob: 0d4873d67787e4625b9967bb0a3d9922685336a6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
// +build js
package sync
type WaitGroup struct {
counter int
ch chan struct{}
state1 [3]uint32
}
func (wg *WaitGroup) Add(delta int) {
wg.counter += delta
if wg.counter < 0 {
panic("sync: negative WaitGroup counter")
}
if wg.counter > 0 && wg.ch == nil {
wg.ch = make(chan struct{})
}
if wg.counter == 0 && wg.ch != nil {
close(wg.ch)
wg.ch = nil
}
}
func (wg *WaitGroup) Wait() {
if wg.counter > 0 {
<-wg.ch
}
}
|