Skip to content

Commit 510ed92

Browse files
committed
Factored runUpdateSender subroutine
1 parent 6fe20d3 commit 510ed92

File tree

1 file changed

+2
-29
lines changed

1 file changed

+2
-29
lines changed

sync_windows.go

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,14 @@ package main
1919

2020
import (
2121
"context"
22-
"time"
2322

2423
"github.com/arduino/go-win32-utils/devicenotification"
2524
discovery "github.com/arduino/pluggable-discovery-protocol-handler/v2"
2625
)
2726

2827
func (d *DFUDiscovery) sync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
2928
ctx, cancel := context.WithCancel(context.Background())
30-
d.close = cancel
31-
32-
deviceEventChan := make(chan bool, 1)
29+
deviceEventChan := d.runUpdateSender(ctx, eventCB, errorCB)
3330
go func() {
3431
err := devicenotification.Start(ctx, func() {
3532
select {
@@ -42,30 +39,6 @@ func (d *DFUDiscovery) sync(eventCB discovery.EventCallback, errorCB discovery.E
4239
}
4340
}()
4441

45-
go func() {
46-
d.sendUpdates(eventCB, errorCB)
47-
48-
for {
49-
select {
50-
case <-ctx.Done():
51-
return
52-
case <-deviceEventChan:
53-
}
54-
55-
again:
56-
d.sendUpdates(eventCB, errorCB)
57-
58-
// Trigger another update after 500ms because Windows might signal a
59-
// new port much before it becomes actually available.
60-
select {
61-
case <-ctx.Done():
62-
return
63-
case <-deviceEventChan:
64-
goto again
65-
case <-time.After(time.Millisecond * 500):
66-
}
67-
d.sendUpdates(eventCB, errorCB)
68-
}
69-
}()
42+
d.close = cancel
7043
return nil
7144
}

0 commit comments

Comments
 (0)