Skip to content

Commit

Permalink
pin add: move creation of timer to the outside of the loop
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed Feb 13, 2017
1 parent 4b2da01 commit d045e89
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions core/commands/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,11 @@ var addPinCmd = &cmds.Command{
out := make(chan interface{})
res.SetOutput((<-chan interface{})(out))
go func() {
duration := 500 * time.Millisecond
timer := time.NewTimer(duration)
defer timer.Stop()
defer close(out)
for {
timer := time.NewTimer(500 * time.Millisecond)
defer timer.Stop()
select {
case val, ok := <-ch:
if !ok {
Expand All @@ -110,6 +111,7 @@ var addPinCmd = &cmds.Command{
return
case <-timer.C:
out <- &AddPinOutput{Progress: v.Value()}
timer.Reset(duration)
case <-ctx.Done():
res.SetError(ctx.Err(), cmds.ErrNormal)
return
Expand Down

0 comments on commit d045e89

Please sign in to comment.