github.com/EagleQL/Xray-core@v1.4.3/common/signal/notifier.go (about) 1 package signal 2 3 // Notifier is a utility for notifying changes. The change producer may notify changes multiple time, and the consumer may get notified asynchronously. 4 type Notifier struct { 5 c chan struct{} 6 } 7 8 // NewNotifier creates a new Notifier. 9 func NewNotifier() *Notifier { 10 return &Notifier{ 11 c: make(chan struct{}, 1), 12 } 13 } 14 15 // Signal signals a change, usually by producer. This method never blocks. 16 func (n *Notifier) Signal() { 17 select { 18 case n.c <- struct{}{}: 19 default: 20 } 21 } 22 23 // Wait returns a channel for waiting for changes. The returned channel never gets closed. 24 func (n *Notifier) Wait() <-chan struct{} { 25 return n.c 26 }