-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: add Done() bool method to sync.Once #41690
Comments
No need for this. Just call once.Do as many times as you want. When it returns, the operation is done and you can proceed. |
@andybons @robpike Proposed method will return status without blocking or performing real work. func (o *Once) Done() bool {return atomic.LoadUint32(&o.done) == 1} |
Usecase 1: Usecase 2: Why do you want to do this? Optimization? If you just want something to initialize, initialize it. Just call |
@DeedleFake status checker routine may not want to The reason why someone is using I feel that if |
I don't understand the point of this request. There are three things that might happen.
|
I'm going to close this issue. |
Thanks everyone for your time. I guess it's a special usecase & pretty easy to implement own custom sync.Once. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
sync.Once.Do()
is nice utility for doing one-time initialization or clean-up.I often miss
Once.Done()
, which will be useful forUsecase 1: A separate go-routine or a web service is continuously polling the status of work.
Usecase 2: All methods first checks initialization, then does real work. Below is the current way to handle this.
Since
sync.Once
already checks adone
flag before calling Do(), it is natural for it to expose it.I propose to add below
Done()
method tosync.Once
struct.This would help avoid clients duplicating it with potentially bug-prone atomic operations.
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: