Defer channel close

This commit is contained in:
Arnaud 2025-10-23 09:47:39 +02:00
parent bc8bbf4172
commit a9fd02863c
No known key found for this signature in database
GPG Key ID: 20E40A5D3110766F
2 changed files with 8 additions and 2 deletions

View File

@ -210,7 +210,11 @@ func (node CodexNode) DownloadStream(ctx context.Context, cid string, options Do
return bridge.callError("cGoCodexDownloadLocal")
}
// Create a done channel to signal the goroutine to stop
// when the download is complete and avoid goroutine leaks.
done := make(chan struct{})
defer close(done)
channelError := make(chan error, 1)
go func() {
select {
@ -222,7 +226,6 @@ func (node CodexNode) DownloadStream(ctx context.Context, cid string, options Do
}()
_, err = bridge.wait()
close(done)
// Extract the potential cancellation error
var cancelError error

View File

@ -305,7 +305,11 @@ func (node CodexNode) UploadFile(ctx context.Context, options UploadOptions) (st
return "", bridge.callError("cGoCodexUploadFile")
}
// Create a done channel to signal the goroutine to stop
// when the download is complete and avoid goroutine leaks.
done := make(chan struct{})
defer close(done)
channelError := make(chan error, 1)
go func() {
select {
@ -317,7 +321,6 @@ func (node CodexNode) UploadFile(ctx context.Context, options UploadOptions) (st
}()
_, err = bridge.wait()
close(done)
// Extract the potential cancellation error
var cancelErr error