Skip to content

Commit

Permalink
Merge pull request #31 from gustavosbarreto/master
Browse files Browse the repository at this point in the history
PollState: change to update-check state after ticks are delivered
  • Loading branch information
Giulian Vivan committed Mar 31, 2017
2 parents 3b3fa5e + ab65177 commit 8094192
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions states.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,20 +185,20 @@ func (state *PollState) Handle(uh *UpdateHub) (State, bool) {
go func() {
ticks := state.ticksCount

polling:
for {
if ticks > 0 && ticks%int64(state.interval/uh.timeStep) == 0 {
nextState = NewUpdateCheckState()
break
}

ticker := time.NewTicker(uh.timeStep)
ticks++

defer ticker.Stop()

select {
case <-ticker.C:
continue
ticks++

if ticks > 0 && ticks%int64(state.interval/uh.timeStep) == 0 {
nextState = NewUpdateCheckState()
break polling
}
case <-state.cancel:
break
}
Expand Down
8 changes: 4 additions & 4 deletions states_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ func TestPolling(t *testing.T) {
expectedElapsedTime time.Duration
}{
{
"Now",
"NextRegularPollFromNow",
10 * time.Second,
now,
0,
10 * time.Second,
},

{
"NextRegularPoll",
"NextRegularPollFromPast",
30 * time.Second,
now.Add(-15 * time.Second),
15 * time.Second,
Expand All @@ -245,7 +245,7 @@ func TestPolling(t *testing.T) {
C: c,
}

c <- time.Now().Add(elapsed * time.Second)
c <- now.Add(elapsed)

return ticker
})
Expand Down

0 comments on commit 8094192

Please sign in to comment.