-
Notifications
You must be signed in to change notification settings - Fork 78
Remove thunk mutex and use a signal channel and atomic pointer #118
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
Merged
pavelnikolov
merged 2 commits into
graph-gophers:master
from
harrisonmetz:tmp/no_thunk_mutex
Oct 12, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| module github.com/graph-gophers/dataloader/v7 | ||
|
|
||
| go 1.18 | ||
| go 1.19 | ||
|
|
||
| require ( | ||
| github.com/hashicorp/golang-lru v0.5.4 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resultcan benilwhich would cause a panic. Please, add a nil check!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I see, it can be
nilif the user provided batch function did not set theitems[i]element. Rather than check it each time the thunk is invoked, what if we always ensured that it was never nil.In this loop:
We could check item items[i] was nil and set to a item which an error that indicates that no value was set. What would you like the
errorto be? Should I just make one withfmt.Errorf()or should we declare one as avar ErrNoValueProvided = errors.New("no value provided")so the user could useerrors.Isagainst it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For starters, I'd be happy with just
fmt.Errorf()- at the very least we remove the risk of a panic. Whether you add a specific error for that is up to you - no strong opinion here.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do you imagine that? Can you provide an example, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the initial code also has would panic if
results[i]of the batch function was nil.dataloader/dataloader.go
Lines 264 to 272 in ab5318f
result.value.Errorand result.value` could be nil.I have made a separate to address this with a known error and updated the comment. This way if the batch function doesn't return a result for a given item, we can automatically give it an error result. (Similarly to how it does that if the length of the result isn't the same.)
efe1a00