github.com/goplusjs/gopherjs@v1.2.6-0.20211206034512-f187917453b8/compiler/natives/src/sync/cond.go (about) 1 // +build js 2 3 package sync 4 5 type Cond struct { 6 // fields used by vanilla implementation 7 noCopy noCopy 8 L Locker 9 notify notifyList 10 checker copyChecker 11 12 // fields used by new implementation 13 n int 14 ch chan bool 15 } 16 17 func (c *Cond) Wait() { 18 c.n++ 19 if c.ch == nil { 20 c.ch = make(chan bool) 21 } 22 c.L.Unlock() 23 <-c.ch 24 c.L.Lock() 25 } 26 27 func (c *Cond) Signal() { 28 if c.n == 0 { 29 return 30 } 31 c.n-- 32 c.ch <- true 33 } 34 35 func (c *Cond) Broadcast() { 36 n := c.n 37 c.n = 0 38 for i := 0; i < n; i++ { 39 c.ch <- true 40 } 41 }