Changes to change system.
the build was successful

This commit is contained in:
2019-06-16 10:32:34 +02:00
parent 13f82399ef
commit 021f67ea4b
19 changed files with 503 additions and 87 deletions
+44
View File
@@ -0,0 +1,44 @@
package notifier
import (
"context"
"sync"
)
// A Notifier is a synchronization primitive for waking upp all listeners at once.
type Notifier struct {
mutex sync.Mutex
ch chan struct{}
}
// Broadcast wakes all listeners if there are any.
func (notifier *Notifier) Broadcast() {
notifier.mutex.Lock()
if notifier.ch != nil {
close(notifier.ch)
notifier.ch = nil
}
notifier.mutex.Unlock()
}
// C gets the channel that'll close on the next notification.
func (notifier *Notifier) C() <-chan struct{} {
notifier.mutex.Lock()
if notifier.ch == nil {
notifier.ch = make(chan struct{})
}
ch := notifier.ch
notifier.mutex.Unlock()
return ch
}
// Wait waits for the next `Broadcast` call, or the context's termination.
func (notifier *Notifier) Wait(ctx context.Context) error {
select {
case <-notifier.C():
return nil
case <-ctx.Done():
return ctx.Err()
}
}