Skip to content
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: there should be a multicloser #20136

Closed
GrimTheReaper opened this issue Apr 26, 2017 · 15 comments
Closed

proposal: io: there should be a multicloser #20136

GrimTheReaper opened this issue Apr 26, 2017 · 15 comments

Comments

@GrimTheReaper
Copy link

GrimTheReaper commented Apr 26, 2017

I propose there be a multi-closer like struct inside of io/multi.go. The purpose would be that multiple close objects could be returned under one. Since there are already multi objects, (ie: reader/writer), it makes sense to me to also include multistructs for other things as well, including io.closer.

https://go-review.googlesource.com/c/41814/

@GrimTheReaper GrimTheReaper changed the title There should be a multicloser in src/io/multi.go io: there should be a multicloser Apr 26, 2017
@bradfitz
Copy link
Contributor

Where would this be used?

Generally we don't add things to the standard library unless they're common.

See also: https://golang.org/doc/faq#x_in_std

@bradfitz bradfitz changed the title io: there should be a multicloser proposal: io: there should be a multicloser Apr 26, 2017
@gopherbot gopherbot added this to the Proposal milestone Apr 26, 2017
@IngCr3at1on
Copy link

I would imagine this would get somewhere around the same amount of usage as a MultiWriter or MultiReader (which I can't say I've ever had a reason to use myself lol).

@GrimTheReaper
Copy link
Author

GrimTheReaper commented Apr 26, 2017

@bradfitz
One use would be used where a function must return a closer, while having multiple things to close, in order to fulfill the interface of io.Closer.

But the point of this proposal is to complete the functionality of src/io/multi.go. In my mind it feels like it is missing.

@bradfitz
Copy link
Contributor

One use would be used where a function must return a closer, while having multiple things to close, in order to fulfill the interface of io.Closer.

Yes, but where concretely? Could you find places in the standard library where code would be simplified by using this.

In previous proposals where things are added to the standard library, the commit or the immediately following one updates the standard library to use the new feature. For instance, when I added strings.Contains in e198a50, the following commit b0afb93 used it. When time.Until was added in 67ea710, the following commit 298791a used it. When sort.Slice was added in 22a2bdf, the following commit ad26bb5 used it.

Where would you use this?

But the point of this proposal is to complete the functionality of src/io/multi.go.

That by itself doesn't meet the bar for standard library inclusion, especially this late in the game. It needs to be simplify existing code.

@GrimTheReaper
Copy link
Author

@bradfitz
When you put it like that, it makes sense not to include this into the standard library. I'll be closing this Issue for now.

@ddevault
Copy link

Apologies for bumping this, but it's something I was looking for today. I would like to be able to close a MultiWriter and close all of the underlying io.CloseWriters.

@ddevault
Copy link

ddevault commented May 1, 2018

Just ended up in this thread again after hitting a need for this in an unrelated project.

@ianlancetaylor
Copy link
Contributor

@SirCmpwn I don't think what you are asking for (closing an io.MultiWriter is the same as what this CL is about (closing a set of io.Closer values). An io.MultiWriter is a collection of io.Writer values, not io.WriteCloser values.

@ddevault
Copy link

ddevault commented May 1, 2018

An io.MultiWriter only implements io.Writer, not io.Closer. It cannot be closed.

@ianlancetaylor
Copy link
Contributor

Yes. I guess I'm confused. What are you asking for?

@ddevault
Copy link

ddevault commented May 1, 2018

io.MultiCloser and io.MultiWriteCloser

@ianlancetaylor
Copy link
Contributor

Thanks, but I don't think we're going to do that, per @bradfitz's comment above. they can be written in a third party library just as effectively.

@ddevault
Copy link

ddevault commented May 2, 2018

I don't agree with @bradfitz's argument. Is the purpose of the standard library to serve itself? Of course not. If the use case for users of the standard library is compelling, then the standard library should be updated even if the features don't see internal use within the standard library.

@ianlancetaylor
Copy link
Contributor

But this is the kind of functionality that can easily be written outside of the standard library. For this kind of thing, that is the place to start. Then if it proves to be popular, it can be brought in.

https://golang.org/doc/faq#x_in_std

@ddevault
Copy link

ddevault commented May 2, 2018

I am familiar with that policy, and in most cases I would agree. But this is a case where the new feature is simple and addresses a defect in the stdlib - that we have a MultiWriter but not the equivalents for Closer and WriteCloser doesn't make sense. It's like only a third of the work was done, not like an entirely new feature is being proposed.

@golang golang locked and limited conversation to collaborators May 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants