![dependabot[bot]](/assets/img/avatar_default.png)
Bumps [github.com/containerd/cgroups/v3](https://github.com/containerd/cgroups) from 3.0.2 to 3.0.3. - [Release notes](https://github.com/containerd/cgroups/releases) - [Commits](https://github.com/containerd/cgroups/compare/v3.0.2...v3.0.3) --- updated-dependencies: - dependency-name: github.com/containerd/cgroups/v3 dependency-type: direct:production update-type: version-update:semver-patch ... 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
|
|
}
|