[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
commit 20978b1278
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 {

2
vendor/modules.txt vendored
View file

@ -36,7 +36,7 @@ codeberg.org/gruf/go-fastpath/v2
# codeberg.org/gruf/go-hashenc v1.0.2
## explicit; go 1.16
codeberg.org/gruf/go-hashenc
# codeberg.org/gruf/go-iotools v0.0.0-20221224124424-3386841cb225
# codeberg.org/gruf/go-iotools v0.0.0-20230601182242-d933b07dcbef
## explicit; go 1.19
codeberg.org/gruf/go-iotools
# codeberg.org/gruf/go-kv v1.6.1