1// Copyright 2023 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package bresource
6
7type Resource[T any] struct {
8	name        string
9	initializer Initializer[T]
10	cfg         ResConfig
11	value       T
12}
13
14func Should[T any](r *Resource[T], e error) bool {
15	return r.cfg.ShouldRetry(e)
16}
17
18type ResConfig struct {
19	ShouldRetry func(error) bool
20	TearDown    func()
21}
22
23type Initializer[T any] func(*int) (T, error)
24
25func New[T any](name string, f Initializer[T], cfg ResConfig) *Resource[T] {
26	return &Resource[T]{name: name, initializer: f, cfg: cfg}
27}
28