Fixing invalid use of time.Timer.

Timer fires only once. Needs to be recreated.
This commit is contained in:
Jakub Sobon 2019-02-19 23:37:37 -05:00
parent b53dce0412
commit 36bf99ebc7
No known key found for this signature in database
GPG Key ID: F2451A77FB05D3B7
2 changed files with 3 additions and 5 deletions

View File

@ -89,9 +89,8 @@ func (r *receiver) waitFor(want int, timeout time.Duration) (map[terminalapi.Eve
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
tick := time.NewTimer(5 * time.Millisecond)
defer tick.Stop()
for { for {
tick := time.NewTimer(5 * time.Millisecond)
select { select {
case <-tick.C: case <-tick.C:
ev := r.getEvents() ev := r.getEvents()
@ -106,7 +105,7 @@ func (r *receiver) waitFor(want int, timeout time.Duration) (map[terminalapi.Eve
case <-ctx.Done(): case <-ctx.Done():
ev := r.getEvents() ev := r.getEvents()
return nil, fmt.Errorf("while waiting for events, got %d so far: %v, err: %v", len(ev), ev, ctx.Err()) return nil, fmt.Errorf("while waiting for events, got %d so far: %v, want %d, err: %v", len(ev), ev, want, ctx.Err())
} }
} }
} }

View File

@ -564,9 +564,8 @@ func untilEmpty(timeout time.Duration, q *eventqueue.Unbound) error {
ctx, cancel := context.WithTimeout(context.Background(), timeout) ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel() defer cancel()
tick := time.NewTimer(5 * time.Millisecond)
defer tick.Stop()
for { for {
tick := time.NewTimer(5 * time.Millisecond)
select { select {
case <-tick.C: case <-tick.C:
if q.Empty() { if q.Empty() {