Add Finalize on SIGINT
This commit is contained in:
parent
0512cc756d
commit
bdd9b88327
|
@ -39,14 +39,17 @@ func (c *connection) Connect() bool {
|
|||
}
|
||||
|
||||
func (c *connection) Disconnect() bool {
|
||||
fmt.Println("Disconnecting " + c.Name + "...")
|
||||
return c.Adaptor.Disconnect()
|
||||
}
|
||||
|
||||
func (c *connection) Finalize() bool {
|
||||
fmt.Println("Finalizing " + c.Name + "...")
|
||||
return c.Adaptor.Finalize()
|
||||
}
|
||||
|
||||
func (c *connection) Reconnect() bool {
|
||||
fmt.Println("Reconnecting to " + c.Name + " on port " + c.Port + "...")
|
||||
return c.Adaptor.Reconnect()
|
||||
}
|
||||
|
||||
|
|
18
master.go
18
master.go
|
@ -1,6 +1,10 @@
|
|||
package gobot
|
||||
|
||||
import "runtime"
|
||||
import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
type Master struct {
|
||||
Robots []Robot
|
||||
|
@ -15,10 +19,20 @@ func GobotMaster() *Master {
|
|||
|
||||
func (m *Master) Start() {
|
||||
runtime.GOMAXPROCS(m.NumCPU)
|
||||
|
||||
for s := range m.Robots {
|
||||
go m.Robots[s].startRobot()
|
||||
}
|
||||
select {}
|
||||
|
||||
c := make(chan os.Signal)
|
||||
signal.Notify(c, os.Interrupt)
|
||||
|
||||
for _ = range c {
|
||||
for r := range m.Robots {
|
||||
m.Robots[r].finalizeConnections()
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Master) FindRobot(name string) *Robot {
|
||||
|
|
Loading…
Reference in New Issue