2017-12-27 20:33:42 +00:00
|
|
|
package signal
|
|
|
|
|
|
|
|
type Notifier struct {
|
2018-02-08 14:39:46 +00:00
|
|
|
c chan struct{}
|
2017-12-27 20:33:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewNotifier() *Notifier {
|
|
|
|
return &Notifier{
|
2018-02-08 14:39:46 +00:00
|
|
|
c: make(chan struct{}, 1),
|
2017-12-27 20:33:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Notifier) Signal() {
|
|
|
|
select {
|
2018-02-08 14:39:46 +00:00
|
|
|
case n.c <- struct{}{}:
|
2017-12-27 20:33:42 +00:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 14:39:46 +00:00
|
|
|
func (n *Notifier) Wait() <-chan struct{} {
|
2017-12-27 20:33:42 +00:00
|
|
|
return n.c
|
|
|
|
}
|