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

docs: remove reference to sync.Locker #66

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

ldez
Copy link
Contributor

@ldez ldez commented Jun 27, 2024

The interface sync.Locker is:

type Locker interface {
	Lock()
	Unlock()
}

https://github.com/golang/go/blob/5a18e79687dea15680ff5f799b549fa0efd0cad9/src/sync/mutex.go#L41-L45

But the method signatures of Flock are:

type Foo interface {
	Lock() error
	Unlock() error
}

So to implement sync.Locker interface, a wrapper should be used.

Example:

type Wrapper struct {
	f *Flock
}

func NewWrapper(path string) *Wrapper {
	return &Wrapper{f: flock.New(path)}
}

func (w Wrapper) Lock() {
	err := w.f.Lock()
	if err != nil {
		panic(err)
	}
}

func (w Wrapper) Unlock() {
	err := w.f.Unlock()
	if err != nil {
		panic(err)
	}
}

Fixes #45

@ldez ldez merged commit 0533797 into gofrs:master Jun 27, 2024
13 checks passed
@ldez ldez deleted the fix/readme-sync-locker branch June 27, 2024 01:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: does not implement sync.Locker
1 participant