pool

package
v0.0.0-...-d9ae738 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2013 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type OpenFunc

type OpenFunc func() Resource

Must return a Resource of nil. When nil is returned the pool remains unchanged.

type Pool

type Pool struct {
	Min         int           // minimum resources to keep
	Max         int           // maximum resources to open
	Concurrency int           // number of types a resource can be acquired (concurrently)
	MaxIdle     time.Duration // Time in idle state (no acquire resources) before closing excess resources (keeps at most Min resources)
	Open        OpenFunc      // Function for openeing a resource
	// contains filtered or unexported fields
}

func (*Pool) Acquire

func (p *Pool) Acquire() Resource

Acquire a resource. This function blocks until a resource is available. When Acquire() is called after the pool is stopped it will return nil. Acquired resources MUST ALWAYS be released with Release().

func (*Pool) Release

func (p *Pool) Release(resource Resource)

Release a resource back to the pool.

func (*Pool) Start

func (p *Pool) Start()

Start the pool.

func (*Pool) Stop

func (p *Pool) Stop()

Stop the pool. This functions does't block (Use Wait() to wait for the pool to finish).

func (*Pool) StopAndWait

func (p *Pool) StopAndWait()

Stop the pool. This function blocks until all resources have been returned.

func (*Pool) Wait

func (p *Pool) Wait()

Wait for the pool to finish

type Resource

type Resource interface {
	// Close doesn't return an error as the resources is expected to handle (and log) all errors
	Close()
	IsClosed() bool
}

Jump to

Keyboard shortcuts

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