mirror of
https://github.com/1f349/lavender.git
synced 2024-11-09 22:32:48 +00:00
16 lines
180 B
Go
16 lines
180 B
Go
|
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
|
||
|
}
|