Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrClosed = errors.New("manager closed")
Functions ¶
This section is empty.
Types ¶
type DestroyFunc ¶
type Manager ¶
type Manager[T Resource] interface { // Acquire a managed resource from the manager, may block until the resource is available or the provided context is canceled. Acquire(context.Context) (*Handle[T], error) // Release signals to the manager that the resource is no longer in use by the caller, but can be used by others Release(*Handle[T]) // Destroy signals to the manager that the resource needs to be cleaned up, usually because it is broken Destroy(*Handle[T]) error // Close blocks future calls to Acquire and destroys all allocated resources Close() error }
type Pool ¶
type Pool[T Resource] struct { // contains filtered or unexported fields }
Pool is a Manager that will maintain up to the specified quantity of the managed resource.
func NewPool ¶
func NewPool[T Resource](create CreateFunc[T], destroy DestroyFunc[T], capacity int) (*Pool[T], error)
func (*Pool[T]) Acquire ¶
Acquire will wait until capacity is available on the pool or the provided context is canceled.
- If the context is canceled before capacity is available, ctx.Err() will be returned.
- If capacity becomes available and there is already a resource allocated, it will be returned.
- If capacity becomes available and the resource needs to be allocated, then the proveded CreateFunc will be called. On success, the created resource will be returned. On failure, the error from the CreateFunc will be returned, and the acquired capacity will be released.
type Shareable ¶
type Shareable[T Resource] struct { // contains filtered or unexported fields }
Shareable is a Manager for a shareable resource, it maintains allocation of a single resource and allows multiple callers to acquire it.
func NewShareable ¶
func NewShareable[T Resource](create CreateFunc[T], destroy DestroyFunc[T]) *Shareable[T]
func (*Shareable[T]) Acquire ¶
Acquire will allocate the shareable resource or return it if it is already allocated
Click to show internal directories.
Click to hide internal directories.