pool

package
v0.0.0-...-fe13f99 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2018 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package pool provides pools for io.Closer instances.

The pools automatically close instances no longer in use. Clients should never call Close() directly on a pool managed closer.

Code works like this:

p := pool.New...(...)
...
func someFunc() {
	id, closer := p.Get()
	defer p.Put(id)
	doSomethingWithCloserWithoutClosingIt(closer)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SingleResource

type SingleResource struct {
	// contains filtered or unexported fields
}

SingleResource is a pool of a single closer. Client can change the underlying closer at any time.

func NewSingleResource

func NewSingleResource(closer io.Closer) *SingleResource

NewSingleResource creates a new instance containing just closer.

func (*SingleResource) Get

func (r *SingleResource) Get() (uint64, io.Closer)

Get returns the id and closer of the current closer in this instance. Client should follow each Get call with a deferred Put() call as in the package example.

func (*SingleResource) Put

func (r *SingleResource) Put(id uint64)

Put signals to this instance that caller is done using the associated closer. id is the same id that Get() returned.

func (*SingleResource) Set

func (r *SingleResource) Set(closer io.Closer)

Set sets the closer in this instance

Jump to

Keyboard shortcuts

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