1
2
3
4
5 package bresource
6
7 type Resource[T any] struct {
8 name string
9 initializer Initializer[T]
10 cfg ResConfig
11 value T
12 }
13
14 func Should[T any](r *Resource[T], e error) bool {
15 return r.cfg.ShouldRetry(e)
16 }
17
18 type ResConfig struct {
19 ShouldRetry func(error) bool
20 TearDown func()
21 }
22
23 type Initializer[T any] func(*int) (T, error)
24
25 func New[T any](name string, f Initializer[T], cfg ResConfig) *Resource[T] {
26 return &Resource[T]{name: name, initializer: f, cfg: cfg}
27 }
28
View as plain text