Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Resource ¶
type Resource struct { // The number of times this resource was fetched from the pool. Uses int // The time.Now().Unix() for when this object was created. CreatedAt int64 // The created resource. Resource interface{} // The pool this resource came from. Pool *ResourcePool }
A resource record.
type ResourceManager ¶
type ResourceManager interface { // Create a resource and return it. Create() (interface{}, error) // Check if a resource should be destroyed. Check(interface{}) error // Destroy a resource. Destroy(interface{}) error }
How to move a resource through its lifetime. Create, Check, and Destroy.
type ResourcePool ¶
type ResourcePool struct { MaxUses int MaxAge int64 ResourceManager ResourceManager FreeResources chan *Resource CreateResources chan int }
func NewResourcePool ¶
func NewResourcePool( resourceManager ResourceManager, maxInstances int, maxUses int, maxAge int64, ) (*ResourcePool, error)
func (*ResourcePool) DestroyResource ¶
func (pool *ResourcePool) DestroyResource(r *Resource) error
func (*ResourcePool) GetResource ¶
func (pool *ResourcePool) GetResource() (*Resource, error)
func (*ResourcePool) ReturnResource ¶
func (pool *ResourcePool) ReturnResource(r *Resource) error
func (*ResourcePool) UseResource ¶
func (pool *ResourcePool) UseResource(f func(*Resource) error) error
Click to show internal directories.
Click to hide internal directories.