-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: io: add CloserFunc and WriterAndCloser #56373
Comments
Your GitHub search seems to find a lot of cases of functions named |
This seems like two separate proposals which happen to compose together but which could be discussed independently. I agree that the first part -- The When I most recently had that need I optimistically looked into the func ReaderWithClose(r io.Reader, close func () error) io.ReadCloser ...which is a similar idea as the existing I ended up just implementing this myself, since of course the implementation was pretty trivial for my specific case: type readerWithClose struct {
io.Reader
close func() error
}
func ReaderWithClose(r io.Reader, close func() error) io.ReadCloser {
return readerWithClose{
Reader: r,
close: close,
}
}
func (r readerWithClose) Close() error {
return r.close()
} I considered generalizing it into a reusable library but found some interesting questions when considering use-cases beyond my immediate need:
Of course I realize that I'm talking about readers while the original proposal was talking about writers, and so my details here are off-topic. But I'm sharing this because I think there are equivalent questions for (The question of whether the second argument to this function should be just a function or an |
can add CloserFunc and WriterAndCloser
CloserFunc is:
WriterAndCloser is:
see: https://github.com/search?q=CloserFunc+language%3Ago&type=code
The text was updated successfully, but these errors were encountered: