You can do the same with OnceValue, but neither is a good idea
as it totally invalidates what sync.Once is good for: preventing
data races which your "reset" (in quotation marks as you do not
reset the sync.Once) provokes.
V.
On Friday, 22 November 2024 at 09:52:59 UTC+1 Hartmut Wieselburger wrote:
> var configOnce sync.Once
> func Reset() {
> configOnce = sync.Once{}
> }
>
> func Load() *Config {
> configOnce.Do(func() {
> ...
> }
>
> burak serdar schrieb am Donnerstag, 21. November 2024 um 21:24:40 UTC+1:
>
>> On Thu, Nov 21, 2024 at 1:14 PM 'Hartmut Wieselburger' via golang-nuts
>> <[email protected]> wrote:
>> >
>> > Hi,
>> > is there a way to reset sync.OnceValue(s), as you can do it with
>> sync.Once?
>>
>> How can you reset a sync.Once?
>>
>> > A common use case is loading a config. I would like to switch from
>> sync.Once to sync.OnceValue, but I need to a chance to reload my config,
>> without restarting my service.
>> > If this is possible with sync.OnceValue, please let me know. Otherwise
>> the new OnceValue(s) are useless for me.
>> >
>> > Regards, Harti
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> Groups "golang-nuts" group.
>> > To unsubscribe from this group and stop receiving emails from it, send
>> an email to [email protected].
>> > To view this discussion visit
>> https://groups.google.com/d/msgid/golang-nuts/46b4a4ff-18cd-494a-9ac0-3a40cf2074e2n%40googlegroups.com.
>>
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/golang-nuts/49b8be35-ff05-43aa-ade3-612c2c7d9acen%40googlegroups.com.