[performance] wrap httpclient response body to ensure drained before close (#1854)

Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
kim
2023-06-02 09:34:52 +01:00
committed by GitHub
parent 55aacaf4b0
commit 20978b1278
5 changed files with 33 additions and 10 deletions

View File

@@ -17,6 +17,14 @@ func CloserCallback(c io.Closer, cb func()) io.Closer {
})
}
func CloserAfterCallback(c io.Closer, cb func()) io.Closer {
return CloserFunc(func() (err error) {
defer func() { err = c.Close() }()
cb()
return
})
}
// CloseOnce wraps an io.Closer to ensure it only performs the close logic once.
func CloseOnce(c io.Closer) io.Closer {
return CloserFunc(func() error {