pool

package
v0.0.0-...-8cba18c Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2021 License: MIT Imports: 3 Imported by: 2

README

go-common/pool

This repository contains the go-common/pool library.

To install:

go get github.com/ugorji/go-common/pool

Package Documentation

Package pool manages a pool of resources.

Exported Package API

func Must(v interface{}, err error) interface{}
type Action uint8
    const GET Action = iota ...
type Fn func(v interface{}, a Action, currentLen int) (interface{}, error)
type T struct{ ... }
    func New(fn Fn, load, capacity int) (t *T, err error)

Documentation

Overview

Package pool manages a pool of resources.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must(v interface{}, err error) interface{}

Types

type Action

type Action uint8
const (
	GET Action = iota
	PUT
	DISPOSE
)

type Fn

type Fn func(v interface{}, a Action, currentLen int) (interface{}, error)

type T

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

T is a simple structure that maintains a pool. It offloads the heavy duty of whether a value should be returned to the fn function. This way, a user can determine when/how objects are returned.

func New

func New(fn Fn, load, capacity int) (t *T, err error)

Creates a new Pool.

  • fn: callback function called after GET and before PUT. allows user to create new object or modify one.
  • initCapacity: preloads this many by calling Get and Put that many times.

func (*T) Drain

func (p *T) Drain() error

func (*T) Get

func (p *T) Get(t time.Duration) (v interface{}, err error)

func (*T) Put

func (p *T) Put(v interface{}) (err error)

Jump to

Keyboard shortcuts

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