Michal Iskierko 6d31343205 feat: Waku v2 bridge
Issue #12610
2024-02-22 17:07:59 +01:00

37 lines
493 B
Go

package missinggo
import "sync"
type ChanCond struct {
mu sync.Mutex
ch chan struct{}
}
func (me *ChanCond) Wait() <-chan struct{} {
me.mu.Lock()
defer me.mu.Unlock()
if me.ch == nil {
me.ch = make(chan struct{})
}
return me.ch
}
func (me *ChanCond) Signal() {
me.mu.Lock()
defer me.mu.Unlock()
select {
case me.ch <- struct{}{}:
default:
}
}
func (me *ChanCond) Broadcast() {
me.mu.Lock()
defer me.mu.Unlock()
if me.ch == nil {
return
}
close(me.ch)
me.ch = nil
}