internal/component: Move Pool into lazy package

This commit is contained in:
Tom Wiesing 2022-10-17 13:08:42 +02:00
parent bcfd0765b0
commit 7c3c84e116
No known key found for this signature in database
8 changed files with 261 additions and 139 deletions

31
pkg/lazy/lazy_test.go Normal file
View file

@ -0,0 +1,31 @@
package lazy
import "fmt"
func ExampleLazy() {
var lazy Lazy[int]
// the first invocation to lazy will be called and set the value
fmt.Println(lazy.Get(func() int { return 42 }))
// the second invocation will not call init again, using the first value
fmt.Println(lazy.Get(func() int { return 43 }))
// Set can be used to set a specific value
lazy.Set(0)
fmt.Println(lazy.Get(func() int { panic("never called") }))
// Output: 42
// 42
// 0
}
func ExampleLazy_nil() {
var lazy Lazy[int]
// passing nil as the initialization function causes the zero value to be set
fmt.Println(lazy.Get(nil))
// Output: 0
}