fix mmissing defer for close channel and move make channel up earlier
This commit is contained in:
@@ -107,9 +107,11 @@ func (b *Bus) Start(log *logging.Logger) error {
|
||||
var ctx context.Context
|
||||
ctx, b.Watchdog = context.WithCancel(context.Background())
|
||||
|
||||
b.Send = make(chan *DMX, 1024)
|
||||
|
||||
go func() {
|
||||
var interval time.Duration = 10 * time.Second
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog stopped", b.Name, b.Ip))
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog starting", b.Name, b.Ip))
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
@@ -126,7 +128,7 @@ func (b *Bus) Start(log *logging.Logger) error {
|
||||
interval = 5 * time.Second
|
||||
} else {
|
||||
b.Reachable = true
|
||||
// send data as a heartbeat for the ArtNet Protocol
|
||||
// send data as a heartbeat for she ArtNet Protocol
|
||||
b.Send <- b.Data
|
||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
||||
interval = 30 * time.Second
|
||||
@@ -145,12 +147,11 @@ func (b *Bus) Start(log *logging.Logger) error {
|
||||
return err
|
||||
}
|
||||
|
||||
b.Send = make(chan *DMX, 1024)
|
||||
|
||||
go func() {
|
||||
defer conn.Close()
|
||||
//close send channel
|
||||
close(b.Send)
|
||||
defer close(b.Send)
|
||||
|
||||
for send := range b.Send {
|
||||
_, err = conn.Write(NewArtNetPackage(send))
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user