tulip/utils/once.go

16 lines
180 B
Go
Raw Normal View History

2024-06-02 12:23:22 +01:00
package utils
import "sync"
type Once[T any] struct {
once sync.Once
value T
}
func (o *Once[T]) Do(f func() T) T {
o.once.Do(func() {
o.value = f()
})
return o.value
}