Skip to content

Commit

Permalink
Merge pull request apache#805 from aai/debouncer
Browse files Browse the repository at this point in the history
typo fix: Debouncer
  • Loading branch information
Zariel authored Oct 24, 2016
2 parents 9395dd7 + 42b857f commit 8fddba8
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,4 @@ Bartosz Burclaf <burclaf@gmail.com>
Marcus King <marcusking01@gmail.com>
Andrew de Andrade <andrew@deandrade.com.br>
Robert Nix <robert@nicerobot.org>
Nathan Youngman <git@nathany.com>
14 changes: 7 additions & 7 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"time"
)

type eventDeouncer struct {
type eventDebouncer struct {
name string
timer *time.Timer
mu sync.Mutex
Expand All @@ -17,8 +17,8 @@ type eventDeouncer struct {
quit chan struct{}
}

func newEventDeouncer(name string, eventHandler func([]frame)) *eventDeouncer {
e := &eventDeouncer{
func newEventDebouncer(name string, eventHandler func([]frame)) *eventDebouncer {
e := &eventDebouncer{
name: name,
quit: make(chan struct{}),
timer: time.NewTimer(eventDebounceTime),
Expand All @@ -30,12 +30,12 @@ func newEventDeouncer(name string, eventHandler func([]frame)) *eventDeouncer {
return e
}

func (e *eventDeouncer) stop() {
func (e *eventDebouncer) stop() {
e.quit <- struct{}{} // sync with flusher
close(e.quit)
}

func (e *eventDeouncer) flusher() {
func (e *eventDebouncer) flusher() {
for {
select {
case <-e.timer.C:
Expand All @@ -54,7 +54,7 @@ const (
)

// flush must be called with mu locked
func (e *eventDeouncer) flush() {
func (e *eventDebouncer) flush() {
if len(e.events) == 0 {
return
}
Expand All @@ -66,7 +66,7 @@ func (e *eventDeouncer) flush() {
e.events = make([]frame, 0, eventBufferSize)
}

func (e *eventDeouncer) debounce(frame frame) {
func (e *eventDebouncer) debounce(frame frame) {
e.mu.Lock()
e.timer.Reset(eventDebounceTime)

Expand Down
2 changes: 1 addition & 1 deletion events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestEventDebounce(t *testing.T) {
wg.Add(1)

eventsSeen := 0
debouncer := newEventDeouncer("testDebouncer", func(events []frame) {
debouncer := newEventDebouncer("testDebouncer", func(events []frame) {
defer wg.Done()
eventsSeen += len(events)
})
Expand Down
8 changes: 4 additions & 4 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ type Session struct {
control *controlConn

// event handlers
nodeEvents *eventDeouncer
schemaEvents *eventDeouncer
nodeEvents *eventDebouncer
schemaEvents *eventDebouncer

// ring metadata
hosts []HostInfo
Expand Down Expand Up @@ -112,8 +112,8 @@ func NewSession(cfg ClusterConfig) (*Session, error) {
}
s.connCfg = connCfg

s.nodeEvents = newEventDeouncer("NodeEvents", s.handleNodeEvent)
s.schemaEvents = newEventDeouncer("SchemaEvents", s.handleSchemaEvent)
s.nodeEvents = newEventDebouncer("NodeEvents", s.handleNodeEvent)
s.schemaEvents = newEventDebouncer("SchemaEvents", s.handleSchemaEvent)

s.routingKeyInfoCache.lru = lru.New(cfg.MaxRoutingKeyInfo)

Expand Down

0 comments on commit 8fddba8

Please sign in to comment.