-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Closed
Labels
Milestone
Description
What version of Go are you using (go version)?
go version go1.10.3 linux/amd64
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (go env)?
N/A
What did you do?
Assuming that there are some structure which has Open and Close method. Some initial stuff should be done for only once - so they share a sync.Once to do this.
type St struct {
openOnce *sync.Once
closeOnce *sync.Once
}
func(st *St) Open(){
st.openOnce.Do(func() { ... }) // init
...
}
func(st *St) Close(){
st.closeOnce.Do(func() { ... }) // deinit
...
}But in this case, St can not be opened again after closed because the "sync.Once.Do()" is actually run once.
What did you expect to see?
I hope this struct can be opened for multiple times, I think adding a Reset method is an idea - then we can reset the openOnce in the Close method.
What did you see instead?
There is not a method to reset the state of sync.Once.
cznic