diff options
Diffstat (limited to 'src/signal.go')
-rw-r--r-- | src/signal.go | 53 |
1 files changed, 0 insertions, 53 deletions
diff --git a/src/signal.go b/src/signal.go deleted file mode 100644 index 2cefad4..0000000 --- a/src/signal.go +++ /dev/null @@ -1,53 +0,0 @@ -package main - -type Signal struct { - enabled AtomicBool - C chan struct{} -} - -func NewSignal() (s Signal) { - s.C = make(chan struct{}, 1) - s.Enable() - return -} - -func (s *Signal) Disable() { - s.enabled.Set(false) - s.Clear() -} - -func (s *Signal) Enable() { - s.enabled.Set(true) -} - -/* Unblock exactly one listener - */ -func (s *Signal) Send() { - if s.enabled.Get() { - select { - case s.C <- struct{}{}: - default: - } - } -} - -/* Clear the signal if already fired - */ -func (s Signal) Clear() { - select { - case <-s.C: - default: - } -} - -/* Unblocks all listeners (forever) - */ -func (s Signal) Broadcast() { - close(s.C) -} - -/* Wait for the signal - */ -func (s Signal) Wait() chan struct{} { - return s.C -} |