mirror of
https://github.com/opencontainers/runc.git
synced 2025-11-03 01:43:44 +08:00
Bumps [github.com/cilium/ebpf](https://github.com/cilium/ebpf) from 0.10.0 to 0.11.0. - [Release notes](https://github.com/cilium/ebpf/releases) - [Commits](https://github.com/cilium/ebpf/compare/v0.10.0...v0.11.0) --- updated-dependencies: - dependency-name: github.com/cilium/ebpf dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
27 lines
480 B
Go
27 lines
480 B
Go
package internal
|
|
|
|
import (
|
|
"sync"
|
|
)
|
|
|
|
type memoizedFunc[T any] struct {
|
|
once sync.Once
|
|
fn func() (T, error)
|
|
result T
|
|
err error
|
|
}
|
|
|
|
func (mf *memoizedFunc[T]) do() (T, error) {
|
|
mf.once.Do(func() {
|
|
mf.result, mf.err = mf.fn()
|
|
})
|
|
return mf.result, mf.err
|
|
}
|
|
|
|
// Memoize the result of a function call.
|
|
//
|
|
// fn is only ever called once, even if it returns an error.
|
|
func Memoize[T any](fn func() (T, error)) func() (T, error) {
|
|
return (&memoizedFunc[T]{fn: fn}).do
|
|
}
|