1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-05 16:55:27 -05:00
This commit is contained in:
Darien Raymond
2018-02-11 23:28:42 +01:00
parent 997c852be8
commit 20fc4950b2
4 changed files with 29 additions and 5 deletions

View File

@@ -1,15 +1,18 @@
package signal
// Notifier is an utility for notifying changes. The change producer may notify changes multiple time, and the consumer may get notified asychronously.
type Notifier struct {
c chan struct{}
}
// NewNotifier creates a new Notifier.
func NewNotifier() *Notifier {
return &Notifier{
c: make(chan struct{}, 1),
}
}
// Signal signals a change, usually by producer. This method never blocks.
func (n *Notifier) Signal() {
select {
case n.c <- struct{}{}:
@@ -17,6 +20,7 @@ func (n *Notifier) Signal() {
}
}
// Wait returns a channel for waiting for changes. The returned channel never gets closed.
func (n *Notifier) Wait() <-chan struct{} {
return n.c
}