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
|
var ctx context.Context
|
||||||
ctx, b.Watchdog = context.WithCancel(context.Background())
|
ctx, b.Watchdog = context.WithCancel(context.Background())
|
||||||
|
|
||||||
|
b.Send = make(chan *DMX, 1024)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
var interval time.Duration = 10 * time.Second
|
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 {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
@@ -126,7 +128,7 @@ func (b *Bus) Start(log *logging.Logger) error {
|
|||||||
interval = 5 * time.Second
|
interval = 5 * time.Second
|
||||||
} else {
|
} else {
|
||||||
b.Reachable = true
|
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
|
b.Send <- b.Data
|
||||||
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
log.Info("bus.Start", fmt.Sprintf("device:%s ip:%s watchdog running", b.Name, b.Ip))
|
||||||
interval = 30 * time.Second
|
interval = 30 * time.Second
|
||||||
@@ -145,12 +147,11 @@ func (b *Bus) Start(log *logging.Logger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
b.Send = make(chan *DMX, 1024)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
//close send channel
|
//close send channel
|
||||||
close(b.Send)
|
defer close(b.Send)
|
||||||
|
|
||||||
for send := range b.Send {
|
for send := range b.Send {
|
||||||
_, err = conn.Write(NewArtNetPackage(send))
|
_, err = conn.Write(NewArtNetPackage(send))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Reference in New Issue
Block a user