client: ImagePullResponse: use sync.OnceValue
| ... | ... |
@@ -16,15 +16,18 @@ import ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
func newImagePullResponse(rc io.ReadCloser) ImagePullResponse {
|
| 19 |
+ if rc == nil {
|
|
| 20 |
+ panic("nil io.ReadCloser")
|
|
| 21 |
+ } |
|
| 19 | 22 |
return ImagePullResponse{
|
| 20 | 23 |
rc: rc, |
| 21 |
- close: &sync.Once{},
|
|
| 24 |
+ close: sync.OnceValue(rc.Close), |
|
| 22 | 25 |
} |
| 23 | 26 |
} |
| 24 | 27 |
|
| 25 | 28 |
type ImagePullResponse struct {
|
| 26 | 29 |
rc io.ReadCloser |
| 27 |
- close *sync.Once |
|
| 30 |
+ close func() error |
|
| 28 | 31 |
} |
| 29 | 32 |
|
| 30 | 33 |
// Read implements io.ReadCloser |
| ... | ... |
@@ -40,13 +43,7 @@ func (r ImagePullResponse) Close() error {
|
| 40 | 40 |
if r.close == nil {
|
| 41 | 41 |
return nil |
| 42 | 42 |
} |
| 43 |
- var err error |
|
| 44 |
- r.close.Do(func() {
|
|
| 45 |
- if r.rc != nil {
|
|
| 46 |
- err = r.rc.Close() |
|
| 47 |
- } |
|
| 48 |
- }) |
|
| 49 |
- return err |
|
| 43 |
+ return r.close() |
|
| 50 | 44 |
} |
| 51 | 45 |
|
| 52 | 46 |
// JSONMessages decodes the response stream as a sequence of JSONMessages. |
| ... | ... |
@@ -16,15 +16,18 @@ import ( |
| 16 | 16 |
) |
| 17 | 17 |
|
| 18 | 18 |
func newImagePullResponse(rc io.ReadCloser) ImagePullResponse {
|
| 19 |
+ if rc == nil {
|
|
| 20 |
+ panic("nil io.ReadCloser")
|
|
| 21 |
+ } |
|
| 19 | 22 |
return ImagePullResponse{
|
| 20 | 23 |
rc: rc, |
| 21 |
- close: &sync.Once{},
|
|
| 24 |
+ close: sync.OnceValue(rc.Close), |
|
| 22 | 25 |
} |
| 23 | 26 |
} |
| 24 | 27 |
|
| 25 | 28 |
type ImagePullResponse struct {
|
| 26 | 29 |
rc io.ReadCloser |
| 27 |
- close *sync.Once |
|
| 30 |
+ close func() error |
|
| 28 | 31 |
} |
| 29 | 32 |
|
| 30 | 33 |
// Read implements io.ReadCloser |
| ... | ... |
@@ -40,13 +43,7 @@ func (r ImagePullResponse) Close() error {
|
| 40 | 40 |
if r.close == nil {
|
| 41 | 41 |
return nil |
| 42 | 42 |
} |
| 43 |
- var err error |
|
| 44 |
- r.close.Do(func() {
|
|
| 45 |
- if r.rc != nil {
|
|
| 46 |
- err = r.rc.Close() |
|
| 47 |
- } |
|
| 48 |
- }) |
|
| 49 |
- return err |
|
| 43 |
+ return r.close() |
|
| 50 | 44 |
} |
| 51 | 45 |
|
| 52 | 46 |
// JSONMessages decodes the response stream as a sequence of JSONMessages. |