Source file test/fixedbugs/issue59709.dir/bresource.go

     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  
     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