Skip to content

gRPC: Added progress callback in CompileServerToStreams adapter #2623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading