@@ -390,21 +390,17 @@ func runProgramAction(pme *packagemanager.Explorer,
390
390
uploadProperties .Set ("build.project_name" , sketchName )
391
391
}
392
392
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 ()
404
396
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 )
407
402
} else {
403
+ updatedUploadPort .Send (nil )
408
404
go f .DiscardCh (watch )
409
405
}
410
406
@@ -520,8 +516,10 @@ func runProgramAction(pme *packagemanager.Explorer,
520
516
}
521
517
}
522
518
519
+ uploadCompleted ()
523
520
logrus .Tracef ("Upload successful" )
524
- return uploadCompleted (), nil
521
+
522
+ return updatedUploadPort .Await (), nil
525
523
}
526
524
527
525
func detectUploadPort (uploadPort * rpc.Port , watch <- chan * rpc.BoardListWatchResponse , uploadCtx context.Context , result f.Future [* rpc.Port ]) {
0 commit comments