Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package signal
 
// Notifier is a utility for notifying changes. The change producer may notify changes multiple time, and the consumer may get notified asynchronously.
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{}{}:
    default:
    }
}
 
// Wait returns a channel for waiting for changes. The returned channel never gets closed.
func (n *Notifier) Wait() <-chan struct{} {
    return n.c
}