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: sync: RWLocker interface #19728

Closed
vitalyisaev2 opened this issue Mar 27, 2017 · 2 comments
Closed

Proposal: sync: RWLocker interface #19728

vitalyisaev2 opened this issue Mar 27, 2017 · 2 comments

Comments

@vitalyisaev2
Copy link

Since we already have sync.Locker interface, it would be pretty nice to have sync.RWLocker interface with two additional methods:

package sync

struct RWLocker interface {
    Locker
    RLock()
    RUnlock()
}

I suggest it will be widely disseminated for the purposes of mocking (e.g. mocking structs with embedded mocks).

@mvdan mvdan added the Proposal label Mar 27, 2017
@mvdan mvdan added this to the Proposal milestone Mar 27, 2017
@mvdan mvdan changed the title Proposal: sync.RWLocker interface Proposal: sync: RWLocker interface Mar 27, 2017
@mvdan
Copy link
Member

mvdan commented Mar 27, 2017

I assume this is just for convenience - you could define this interface outside of the standard library and it would work just as fine.

@bradfitz
Copy link
Contributor

The only reason that the sync package has Locker is because https://golang.org/pkg/sync/#NewCond takes a Locker.

We don't proactively add interfaces for things users might want.

If you need an interface, you can define it yourself, as @mvdan says. That's one of the nice things about implicitly implementing interfaces.

@golang golang locked and limited conversation to collaborators Mar 27, 2018
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

4 participants