lazyget

package
v0.0.62 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 15, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

Documentation

Overview

Package lazyget provides a simple way to create thread-safe, type-safe getter functions to lazily initialize, cache, and return a value of a given type. It uses a sync.Once to ensure that the initialization function is only called once, even in concurrent environments. All subsequent calls will return the cached value.

Usage:

var GetResource = lazyget.New(func() *Resource {
	// do some expensive initialization here
	return &Resource{}
})

r := GetResource() // r is of type *Resource

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New[T any](initFunc func() T) func() T

New takes an initialization function and returns a getter function that will lazily initialize, cache, and return a value of type T.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL