Skip to content

Commit

Permalink
Merge pull request #74 from rogpeppe/001-hide-mutex
Browse files Browse the repository at this point in the history
loadbalancer: do not expose sync.Mutex as public field
  • Loading branch information
peterbourgon committed Jul 10, 2015
2 parents 6939b5c + 0592c39 commit 0e73ced
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 0e73ced

Please sign in to comment.