Skip to content

Commit

Permalink
loadbalancer: do not expose sync.Mutex as public field
Browse files Browse the repository at this point in the history
  • Loading branch information
rogpeppe committed Jul 10, 2015
1 parent 6939b5c commit 0592c39
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions loadbalancer/static_publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ func NewStaticPublisher(endpoints []endpoint.Endpoint) *StaticPublisher {

// StaticPublisher holds a static set of endpoints.
type StaticPublisher struct {
sync.Mutex
mu sync.Mutex
current []endpoint.Endpoint
subscribers map[chan<- []endpoint.Endpoint]struct{}
}

// Subscribe implements Publisher.
func (p *StaticPublisher) Subscribe(c chan<- []endpoint.Endpoint) {
p.Lock()
defer p.Unlock()
p.mu.Lock()
defer p.mu.Unlock()
p.subscribers[c] = struct{}{}
c <- p.current
}

// Unsubscribe implements Publisher.
func (p *StaticPublisher) Unsubscribe(c chan<- []endpoint.Endpoint) {
p.Lock()
defer p.Unlock()
p.mu.Lock()
defer p.mu.Unlock()
delete(p.subscribers, c)
}

Expand All @@ -42,8 +42,8 @@ func (p *StaticPublisher) Stop() {}

// Replace replaces the endpoints and notifies all subscribers.
func (p *StaticPublisher) Replace(endpoints []endpoint.Endpoint) {
p.Lock()
defer p.Unlock()
p.mu.Lock()
defer p.mu.Unlock()
p.current = endpoints
for c := range p.subscribers {
c <- p.current
Expand Down

0 comments on commit 0592c39

Please sign in to comment.