Skip to content

Commit

Permalink
Fix stack trace on close
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Dec 23, 2014
1 parent e4811ad commit c16993a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions platforms/joystick/joystick_driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type JoystickDriver struct {
configPath string
config joystickConfig
poll func() sdl.Event
halt chan bool
gobot.Eventer
}

Expand Down Expand Up @@ -60,6 +61,7 @@ func NewJoystickDriver(a *JoystickAdaptor, name string, config string, v ...time
return sdl.PollEvent()
},
interval: 10 * time.Millisecond,
halt: make(chan bool, 0),
}

if len(v) > 0 {
Expand Down Expand Up @@ -107,14 +109,21 @@ func (j *JoystickDriver) Start() (errs []error) {
gobot.Publish(j.Event("error"), err)
}
}
<-time.After(j.interval)
select {
case <-time.After(j.interval):
case <-j.halt:
return
}
}
}()
return
}

// Halt stops joystick driver
func (j *JoystickDriver) Halt() (errs []error) { return }
func (j *JoystickDriver) Halt() (errs []error) {
j.halt <- true
return
}

// HandleEvent publishes an specific event according to data received
func (j *JoystickDriver) handleEvent(event sdl.Event) error {
Expand Down
3 changes: 3 additions & 0 deletions platforms/joystick/joystick_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func TestJoystickDriverStart(t *testing.T) {

func TestJoystickDriverHalt(t *testing.T) {
d := initTestJoystickDriver()
go func() {
<-d.halt
}()
gobot.Assert(t, len(d.Halt()), 0)
}

Expand Down

0 comments on commit c16993a

Please sign in to comment.