rpool

package module
v0.0.0-...-f18321c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 12, 2015 License: BSD-3-Clause Imports: 7 Imported by: 5

README

Documentation

Overview

Package rpool provides a resource pool.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	// New is used to create a new resource when necessary.
	New func() (io.Closer, error)

	// CloseErrorHandler will be called when an error occurs closing a resource.
	CloseErrorHandler func(err error)

	// Stats is optional and allows for the pool to provide stats for various
	// interesting events in the pool.
	Stats stats.Client

	// Max defines the maximum number of concurrently allocated resources.
	Max uint

	// MinIdle defines the number of minimum idle resources. These number of
	// resources are kept around when the idle cleanup kicks in.
	MinIdle uint

	// IdleTimeout defines the duration of idle time after which a resource will
	// be closed.
	IdleTimeout time.Duration

	// ClosePoolSize defines the number of concurrent goroutines that will close
	// resources.
	ClosePoolSize uint

	// Clock allows for testing timing related functionality. Do not specify this
	// in production code.
	Clock clock.Clock
	// contains filtered or unexported fields
}

Pool manages the life cycle of resources.

func (*Pool) Acquire

func (p *Pool) Acquire() (io.Closer, error)

Acquire will pull a resource from the pool or create a new one if necessary.

func (*Pool) Close

func (p *Pool) Close() error

Close closes the pool and its resources. It waits until all acquired resources are released or discarded. It is an error to call Acquire after closing the pool.

func (*Pool) Discard

func (p *Pool) Discard(c io.Closer)

Discard closes the resource and indicates we're throwing it away. It will panic if you try to discard a resource that wasn't acquired from this pool.

func (*Pool) Release

func (p *Pool) Release(c io.Closer)

Release puts the resource back into the pool. It will panic if you try to release a resource that wasn't acquired from this pool.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL