Skip to content

Commit 405a810

Browse files
committed
Moved FeedStreamTo and ConsumeStreamFrom into deamon package and mde them private
1 parent 2f59e6a commit 405a810

File tree

4 files changed

+23
-19
lines changed

4 files changed

+23
-19
lines changed

commands/daemon/daemon.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"io"
2323

2424
"github.com/arduino/arduino-cli/arduino"
25-
"github.com/arduino/arduino-cli/arduino/utils"
2625
"github.com/arduino/arduino-cli/commands"
2726
"github.com/arduino/arduino-cli/commands/board"
2827
"github.com/arduino/arduino-cli/commands/compile"
@@ -259,8 +258,8 @@ func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSke
259258

260259
// Compile FIXMEDOC
261260
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileRequest, stream rpc.ArduinoCoreService_CompileServer) error {
262-
outStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResponse{OutStream: data}) })
263-
errStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResponse{ErrStream: data}) })
261+
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResponse{OutStream: data}) })
262+
errStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.CompileResponse{ErrStream: data}) })
264263
compileResp, compileErr := compile.Compile(
265264
stream.Context(), req, outStream, errStream,
266265
func(p *rpc.TaskProgress) { stream.Send(&rpc.CompileResponse{Progress: p}) },
@@ -344,8 +343,8 @@ func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.Platf
344343

345344
// Upload FIXMEDOC
346345
func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.ArduinoCoreService_UploadServer) error {
347-
outStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadResponse{OutStream: data}) })
348-
errStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadResponse{ErrStream: data}) })
346+
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.UploadResponse{OutStream: data}) })
347+
errStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.UploadResponse{ErrStream: data}) })
349348
resp, err := upload.Upload(stream.Context(), req, outStream, errStream)
350349
outStream.Close()
351350
errStream.Close()
@@ -357,8 +356,8 @@ func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadRequest, stream rpc.Arduin
357356

358357
// UploadUsingProgrammer FIXMEDOC
359358
func (s *ArduinoCoreServerImpl) UploadUsingProgrammer(req *rpc.UploadUsingProgrammerRequest, stream rpc.ArduinoCoreService_UploadUsingProgrammerServer) error {
360-
outStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResponse{OutStream: data}) })
361-
errStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResponse{ErrStream: data}) })
359+
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResponse{OutStream: data}) })
360+
errStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.UploadUsingProgrammerResponse{ErrStream: data}) })
362361
resp, err := upload.UsingProgrammer(stream.Context(), req, outStream, errStream)
363362
outStream.Close()
364363
errStream.Close()
@@ -376,8 +375,8 @@ func (s *ArduinoCoreServerImpl) SupportedUserFields(ctx context.Context, req *rp
376375

377376
// BurnBootloader FIXMEDOC
378377
func (s *ArduinoCoreServerImpl) BurnBootloader(req *rpc.BurnBootloaderRequest, stream rpc.ArduinoCoreService_BurnBootloaderServer) error {
379-
outStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.BurnBootloaderResponse{OutStream: data}) })
380-
errStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&rpc.BurnBootloaderResponse{ErrStream: data}) })
378+
outStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.BurnBootloaderResponse{OutStream: data}) })
379+
errStream := feedStreamTo(func(data []byte) { stream.Send(&rpc.BurnBootloaderResponse{ErrStream: data}) })
381380
resp, err := upload.BurnBootloader(stream.Context(), req, outStream, errStream)
382381
outStream.Close()
383382
errStream.Close()

commands/daemon/debug.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919
"context"
2020
"os"
2121

22-
"github.com/arduino/arduino-cli/arduino/utils"
2322
cmd "github.com/arduino/arduino-cli/commands/debug"
2423
dbg "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/debug/v1"
2524
"github.com/pkg/errors"
@@ -50,9 +49,9 @@ func (s *DebugService) Debug(stream dbg.DebugService_DebugServer) error {
5049
// Launch debug recipe attaching stdin and out to grpc streaming
5150
signalChan := make(chan os.Signal)
5251
defer close(signalChan)
53-
outStream := utils.FeedStreamTo(func(data []byte) { stream.Send(&dbg.DebugResponse{Data: data}) })
52+
outStream := feedStreamTo(func(data []byte) { stream.Send(&dbg.DebugResponse{Data: data}) })
5453
resp, debugErr := cmd.Debug(stream.Context(), req,
55-
utils.ConsumeStreamFrom(func() ([]byte, error) {
54+
consumeStreamFrom(func() ([]byte, error) {
5655
command, err := stream.Recv()
5756
if command.GetSendInterrupt() {
5857
signalChan <- os.Interrupt

arduino/utils/stream.go renamed to commands/daemon/stream.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to [email protected].
1515

16-
package utils
16+
package daemon
1717

1818
import (
1919
"io"
@@ -38,12 +38,12 @@ func (w *implWriteCloser) Close() error {
3838
return w.close()
3939
}
4040

41-
// FeedStreamTo creates a pipe to pass data to the writer function.
42-
// FeedStreamTo returns the io.WriteCloser side of the pipe, on which the user can write data.
41+
// feedStreamTo creates a pipe to pass data to the writer function.
42+
// feedStreamTo returns the io.WriteCloser side of the pipe, on which the user can write data.
4343
// The user must call Close() on the returned io.WriteCloser to release all the resources.
4444
// If needed, the context can be used to detect when all the data has been processed after
4545
// closing the writer.
46-
func FeedStreamTo(writer func(data []byte)) io.WriteCloser {
46+
func feedStreamTo(writer func(data []byte)) io.WriteCloser {
4747
r, w := nio.Pipe(buffer.New(32 * 1024))
4848
var wg sync.WaitGroup
4949
wg.Add(1)
@@ -77,9 +77,9 @@ func FeedStreamTo(writer func(data []byte)) io.WriteCloser {
7777
}
7878
}
7979

80-
// ConsumeStreamFrom creates a pipe to consume data from the reader function.
81-
// ConsumeStreamFrom returns the io.Reader side of the pipe, which the user can use to consume the data
82-
func ConsumeStreamFrom(reader func() ([]byte, error)) io.Reader {
80+
// consumeStreamFrom creates a pipe to consume data from the reader function.
81+
// consumeStreamFrom returns the io.Reader side of the pipe, which the user can use to consume the data
82+
func consumeStreamFrom(reader func() ([]byte, error)) io.Reader {
8383
r, w := io.Pipe()
8484
go func() {
8585
for {

docs/UPGRADING.md

+6
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,12 @@ must be changed to:
266266
eventsChan, closeWatcher, err := board.Watch(req)
267267
```
268268

269+
### Removed `utils.FeedStreamTo` and `utils.ConsumeStreamFrom`
270+
271+
`github.com/arduino/arduino-cli/arduino/utils.FeedStreamTo` and
272+
`github.com/arduino/arduino-cli/arduino/utils.ConsumeStreamFrom` are now private. They are mainly used internally for
273+
gRPC stream handling and are not suitable to be public API.
274+
269275
## 0.26.0
270276

271277
### `github.com/arduino/arduino-cli/commands.DownloadToolRelease`, and `InstallToolRelease` functions have been removed

0 commit comments

Comments
 (0)