Skip to content

Commit fee84a9

Browse files
committed
Fixed also existing calls to BoardListWatch
1 parent 81a2f49 commit fee84a9

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

internal/cli/arguments/port.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,14 @@ func (p *Port) GetPort(ctx context.Context, instance *rpc.Instance, srv rpc.Ardu
8989
}
9090
logrus.WithField("port", address).Tracef("Upload port")
9191

92-
ctx, cancel := context.WithCancel(ctx)
92+
ctx, cancel := context.WithTimeout(ctx, p.timeout.Get())
9393
defer cancel()
9494

9595
stream, watcher := commands.BoardListWatchProxyToChan(ctx)
96-
err := srv.BoardListWatch(&rpc.BoardListWatchRequest{Instance: instance}, stream)
96+
go func() {
97+
_ = srv.BoardListWatch(&rpc.BoardListWatchRequest{Instance: instance}, stream)
98+
}()
9799

98-
if err != nil {
99-
return nil, err
100-
}
101-
102-
deadline := time.After(p.timeout.Get())
103100
for {
104101
select {
105102
case portEvent := <-watcher:
@@ -111,7 +108,7 @@ func (p *Port) GetPort(ctx context.Context, instance *rpc.Instance, srv rpc.Ardu
111108
return port, nil
112109
}
113110

114-
case <-deadline:
111+
case <-ctx.Done():
115112
// No matching port found
116113
if protocol == "" {
117114
return &rpc.Port{

internal/cli/board/list.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ func runListCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, watch
9191

9292
func watchList(ctx context.Context, inst *rpc.Instance, srv rpc.ArduinoCoreServiceServer) {
9393
stream, eventsChan := commands.BoardListWatchProxyToChan(ctx)
94-
err := srv.BoardListWatch(&rpc.BoardListWatchRequest{Instance: inst}, stream)
95-
if err != nil {
96-
feedback.Fatal(i18n.Tr("Error detecting boards: %v", err), feedback.ErrNetwork)
97-
}
94+
go func() {
95+
err := srv.BoardListWatch(&rpc.BoardListWatchRequest{Instance: inst}, stream)
96+
if err != nil {
97+
feedback.Fatal(i18n.Tr("Error detecting boards: %v", err), feedback.ErrNetwork)
98+
}
99+
}()
98100

99101
// This is done to avoid printing the header each time a new event is received
100102
if feedback.GetFormat() == feedback.Text {

0 commit comments

Comments
 (0)