dushaoshuai / dushaoshuai.github.io

https://www.shuai.host
0 stars 0 forks source link

Go: 使用 sync.Once 修饰函数 #61

Open dushaoshuai opened 1 year ago

dushaoshuai commented 1 year ago

https://github.com/keybase/client/blob/3417310fe7d93574e24e66bd300ddbe2e6dd7217/go/libkb/util.go#L979

func Once(f func()) func() {
    var once sync.Once
    return func() {
        once.Do(f)
    }
}