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

Use locking to solve data race. #141

Merged
merged 4 commits into from
Mar 4, 2022
Merged

Use locking to solve data race. #141

merged 4 commits into from
Mar 4, 2022

Conversation

JackKCWong
Copy link
Contributor

Now the following does not show data race anymore.

cd example/hotreload
cat main.go | go run -race main.go

@JackKCWong JackKCWong mentioned this pull request Feb 28, 2022
Copy link
Owner

@ktr0731 ktr0731 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a nit comment 🙏

option.go Outdated Show resolved Hide resolved
Co-authored-by: ktr <ktr@syfm.me>
@@ -615,8 +617,10 @@ func (f *finder) find(slice interface{}, itemFunc func(i int) string, opts []Opt

inited := make(chan struct{})
if opt.hotReload && rv.Kind() == reflect.Ptr {
opt.hotReloadLock.Lock()
Copy link
Owner

@ktr0731 ktr0731 Mar 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, it looks like when the caller uses WithHotReload, it will panic because opt.hotReloadLock is nil (see CI result).
Could you add a nop locker as the default option for backward-compatibility?

go-fuzzyfinder/option.go

Lines 26 to 28 in 81ff9cb

var defaultOption = opt{
promptString: "> ",
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ya sure. my mistake. My first ever PR, please bear with me :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be passing this time.

go-fuzzyfinder git:(main) go test -race ./...
ok      github.com/ktr0731/go-fuzzyfinder       10.554s
ok      github.com/ktr0731/go-fuzzyfinder/matching      0.638s
ok      github.com/ktr0731/go-fuzzyfinder/scoring       1.046s

@codecov
Copy link

codecov bot commented Mar 4, 2022

Codecov Report

Merging #141 (8ebf630) into master (81ff9cb) will decrease coverage by 0.05%.
The diff coverage is 81.81%.

@@            Coverage Diff             @@
##           master     #141      +/-   ##
==========================================
- Coverage   85.73%   85.67%   -0.06%     
==========================================
  Files           5        5              
  Lines         764      775      +11     
==========================================
+ Hits          655      664       +9     
- Misses         95       97       +2     
  Partials       14       14              

Copy link
Owner

@ktr0731 ktr0731 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
Thanks for your contribution 🎉

@ktr0731 ktr0731 merged commit 8255f49 into ktr0731:master Mar 4, 2022
@ktr0731 ktr0731 mentioned this pull request Mar 4, 2022
@JackKCWong JackKCWong deleted the main branch March 4, 2022 12:27
@JackKCWong
Copy link
Contributor Author

thanks for your time! it is ready to rock in my next side project now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants