Skip to content

Commit

Permalink
[skip-changelog] gRPC: Added progress callback in CompileServerToStre…
Browse files Browse the repository at this point in the history
…ams adapter (#2623)
  • Loading branch information
cmaglie committed Jun 5, 2024
1 parent b72f5ca commit b16ae70
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion commands/service_compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (

// CompilerServerToStreams creates a gRPC CompileServer that sends the responses to the provided streams.
// The returned callback function can be used to retrieve the builder result after the compilation is done.
func CompilerServerToStreams(ctx context.Context, stdOut, stderr io.Writer) (server rpc.ArduinoCoreService_CompileServer, resultCB func() *rpc.BuilderResult) {
func CompilerServerToStreams(ctx context.Context, stdOut, stderr io.Writer, progressCB rpc.TaskProgressCB) (server rpc.ArduinoCoreService_CompileServer, resultCB func() *rpc.BuilderResult) {
var builderResult *rpc.BuilderResult
stream := streamResponseToCallback(ctx, func(resp *rpc.CompileResponse) error {
if out := resp.GetOutStream(); len(out) > 0 {
Expand All @@ -57,6 +57,11 @@ func CompilerServerToStreams(ctx context.Context, stdOut, stderr io.Writer) (ser
if result := resp.GetResult(); result != nil {
builderResult = result
}
if progress := resp.GetProgress(); progress != nil {
if progressCB != nil {
progressCB(progress)
}
}
return nil
})
return stream, func() *rpc.BuilderResult { return builderResult }
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/compile/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
DoNotExpandBuildProperties: showProperties == arguments.ShowPropertiesUnexpanded,
Jobs: jobs,
}
server, builderResCB := commands.CompilerServerToStreams(ctx, stdOut, stdErr)
server, builderResCB := commands.CompilerServerToStreams(ctx, stdOut, stdErr, nil)
compileError := srv.Compile(compileRequest, server)
builderRes := builderResCB()

Expand Down

0 comments on commit b16ae70

Please sign in to comment.