Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit edc3a56

Browse filesBrowse files
committed
Further simplified port detection subroutine structure
1 parent b766614 commit edc3a56
Copy full SHA for edc3a56

File tree

1 file changed

+12
-14
lines changed
Filter options

1 file changed

+12
-14
lines changed

‎commands/upload/upload.go

Copy file name to clipboardExpand all lines: commands/upload/upload.go
+12-14Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,17 @@ func runProgramAction(pme *packagemanager.Explorer,
390390
uploadProperties.Set("build.project_name", sketchName)
391391
}
392392

393-
// By default do not return any new port...
394-
uploadCompleted := func() *rpc.Port { return nil }
395-
// ...but if there is an expected port change then run the detector...
396-
if uploadProperties.GetBoolean("upload.wait_for_upload_port") && watch != nil {
397-
uploadCompletedCtx, cancel := context.WithCancel(context.Background())
398-
newUploadPort := f.NewFuture[*rpc.Port]()
399-
go detectUploadPort(port, watch, uploadCompletedCtx, newUploadPort)
400-
uploadCompleted = func() *rpc.Port {
401-
cancel()
402-
return newUploadPort.Await()
403-
}
393+
// This context is kept alive for the entire duration of the upload
394+
uploadCtx, uploadCompleted := context.WithCancel(context.Background())
395+
defer uploadCompleted()
404396

405-
// Ensures goroutines completion in case of exit on error
406-
defer uploadCompleted()
397+
// By default do not return any new port but if there is an
398+
// expected port change then run the detector.
399+
updatedUploadPort := f.NewFuture[*rpc.Port]()
400+
if uploadProperties.GetBoolean("upload.wait_for_upload_port") && watch != nil {
401+
go detectUploadPort(port, watch, uploadCtx, updatedUploadPort)
407402
} else {
403+
updatedUploadPort.Send(nil)
408404
go f.DiscardCh(watch)
409405
}
410406

@@ -520,8 +516,10 @@ func runProgramAction(pme *packagemanager.Explorer,
520516
}
521517
}
522518

519+
uploadCompleted()
523520
logrus.Tracef("Upload successful")
524-
return uploadCompleted(), nil
521+
522+
return updatedUploadPort.Await(), nil
525523
}
526524

527525
func detectUploadPort(uploadPort *rpc.Port, watch <-chan *rpc.BoardListWatchResponse, uploadCtx context.Context, result f.Future[*rpc.Port]) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.