Debian Codegraph @

compiler/natives/src/sync/waitgroup.go

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