-
Notifications
You must be signed in to change notification settings - Fork 154
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
golang.org/x/sync/singleflight: add Use method to perform cleanup of temp resource after last use #9
base: master
Are you sure you want to change the base?
Conversation
This PR (HEAD: be10acb) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213797 to see it. Tip: You can toggle comments from me using the |
Message from Leonid Gershanovich: Patch Set 2: this PR is a replacement for https://go-review.googlesource.com/c/sync/+/213478 Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Brad Fitzpatrick: Patch Set 2: (4 comments) Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Brad Fitzpatrick: Patch Set 2: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
This PR (HEAD: 5e24338) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213797 to see it. Tip: You can toggle comments from me using the |
Message from Dave Cheney: Patch Set 3: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Brad Fitzpatrick: Patch Set 7: I thought of a nicer (IMO) way to implement this: Instead define an interface like: type SharedValuer interface{ And document that if the fn given to Do (or DoChan) returns an interface{} implementing SharedValuer, then its SharedValue method is called (with the initial refcount) to return the value to each dup caller. Then it's the return value's responsibility to do its own cleanup (e.g. have a Close method and on the final 1->0 refcount transition, close the real underlying resource) Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Leonid Gershanovich: Patch Set 7: (6 comments)
I do not particularly like this approach as it creates a requirement for functor used with singleflight. In other words, if I want to "singleflight" a particular function - it has to be written in a special way. Also this approach means that same chunk of code (implementing SharedValuer interface and Close/decrementing) will have to be repeated by everyone who want to use it, which is more error prone that doing it once. Having said that, your approach will definitely work. Although I am not 100% clear of what I have created this PR with 2 purposes:
Bottom line: if you believe that feature I am requesting will benefit package and community and have a preference how it should be done - I'd be very happy with any implementation. Thanks for considering it Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Bryan C. Mills: Patch Set 7:
I'm not keen on exposing reference-counts at all. What about something more lifetime-oriented? Consider, as an alternative: // Use calls new at most once at a time, then invokes fn with the resulting value. Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Leonid Gershanovich: Patch Set 7:
Couple of small concerns:
will become
Other than that - I do like this approach Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
5e24338
to
b39aa21
Compare
We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for all the commit author(s) or Co-authors. If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google. ℹ️ Googlers: Go here for more info. |
This PR (HEAD: b39aa21) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213797 to see it. Tip: You can toggle comments from me using the |
b39aa21
to
2baeae8
Compare
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Message from Gobot Gobot: Patch Set 8: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
This PR (HEAD: 2baeae8) has been imported to Gerrit for code review. Please visit https://go-review.googlesource.com/c/sync/+/213797 to see it. Tip: You can toggle comments from me using the |
Message from Bryan C. Mills: Patch Set 9: (1 comment) Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Message from Go Bot: Patch Set 8: Congratulations on opening your first change. Thank you for your contribution! Next steps: Most changes in the Go project go through a few rounds of revision. This can be During May-July and Nov-Jan the Go project is in a code freeze, during which Please don’t reply on this GitHub thread. Visit golang.org/cl/213797. |
Background:
We are using singleflight to run expensive procedure that creates a temporary
resource (temp file). Our challenge - we need to determine when it is safe to
cleanup this temp resource.
Currently
Group.Do/DoChan
methods only return ashared bool
indicator,but they do not surface to caller how many actual callers will be using the result.
Proposal to consider:
Currently implementation maintains "dups int" property for each
call
, semanticallyit is almost exactly a "reference counter" except in case of single caller it holds value 0 instead of 1.
I propose, to introduce a new Method
DoRefCount
with signature virtually identicalto one of
Do
method, except instead ofshared bool
it will be returninga
refCount RefCounter
(pointer tocall.dups
), which will hold a pointerto a reference counter (pointer to
call.dups
?)This PR provides an implementation for above
this PR replaces #8