Fix stack trace on close
This commit is contained in:
parent
e4811ad1cb
commit
c16993ab05
|
@ -20,6 +20,7 @@ type JoystickDriver struct {
|
|||
configPath string
|
||||
config joystickConfig
|
||||
poll func() sdl.Event
|
||||
halt chan bool
|
||||
gobot.Eventer
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue