More consistent use of signal struct

This commit is contained in:
Mathias Hall-Andersen
2017-12-01 23:37:26 +01:00
parent cb09125dc4
commit eaca1ee1f7
9 changed files with 68 additions and 68 deletions
+9 -1
View File
@@ -20,6 +20,8 @@ func (s *Signal) Enable() {
s.enabled.Set(true)
}
/* Unblock exactly one listener
*/
func (s *Signal) Send() {
if s.enabled.Get() {
select {
@@ -29,6 +31,8 @@ func (s *Signal) Send() {
}
}
/* Clear the signal if already fired
*/
func (s Signal) Clear() {
select {
case <-s.C:
@@ -36,10 +40,14 @@ func (s Signal) Clear() {
}
}
/* Unblocks all listeners (forever)
*/
func (s Signal) Broadcast() {
close(s.C) // unblocks all selectors
close(s.C)
}
/* Wait for the signal
*/
func (s Signal) Wait() chan struct{} {
return s.C
}