client: ImagePullResponse: use sync.OnceValue

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-10 10:31:36 +02:00
parent 6e4684459d
commit cfdb9068f0
2 changed files with 12 additions and 18 deletions

View File

@@ -16,15 +16,18 @@ import (
)
func newImagePullResponse(rc io.ReadCloser) ImagePullResponse {
if rc == nil {
panic("nil io.ReadCloser")
}
return ImagePullResponse{
rc: rc,
close: &sync.Once{},
close: sync.OnceValue(rc.Close),
}
}
type ImagePullResponse struct {
rc io.ReadCloser
close *sync.Once
close func() error
}
// Read implements io.ReadCloser
@@ -37,13 +40,7 @@ func (r ImagePullResponse) Close() error {
if r.close == nil {
return nil
}
var err error
r.close.Do(func() {
if r.rc != nil {
err = r.rc.Close()
}
})
return err
return r.close()
}
// JSONMessages decodes the response stream as a sequence of JSONMessages.

View File

@@ -16,15 +16,18 @@ import (
)
func newImagePullResponse(rc io.ReadCloser) ImagePullResponse {
if rc == nil {
panic("nil io.ReadCloser")
}
return ImagePullResponse{
rc: rc,
close: &sync.Once{},
close: sync.OnceValue(rc.Close),
}
}
type ImagePullResponse struct {
rc io.ReadCloser
close *sync.Once
close func() error
}
// Read implements io.ReadCloser
@@ -37,13 +40,7 @@ func (r ImagePullResponse) Close() error {
if r.close == nil {
return nil
}
var err error
r.close.Do(func() {
if r.rc != nil {
err = r.rc.Close()
}
})
return err
return r.close()
}
// JSONMessages decodes the response stream as a sequence of JSONMessages.