pooling

package
v0.20.1 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2024 License: GPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pooling implements the wayback workers pool.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPoolNotExist = errors.New("pool not exist")  // ErrPoolNotExist pool not exist
	ErrTimeout      = errors.New("process timeout") // ErrTimeout process timeout

)

Functions

This section is empty.

Types

type Bucket added in v0.18.0

type Bucket struct {
	// Request is the main func for handling wayback requests.
	Request func(context.Context) error

	// Fallback defines an optional func to return a failure response for the Request func.
	Fallback func(context.Context) error
	// contains filtered or unexported fields
}

A Bucket represents a wayback request is sent by a service.

type Option added in v0.19.0

type Option func(*Options)

Option is a function that modifies the provided Options instance.

func Capacity added in v0.19.0

func Capacity(c int) Option

Capacity returns an Option function that sets the capacity value for the Options. The given capacity value will be applied when the returned function is called.

func MaxRetries added in v0.19.0

func MaxRetries(r uint64) Option

MaxRetries returns an Option function that sets the maximum retries value for the Options. The given maximum retries value will be applied when the returned function is called.

func Timeout added in v0.19.0

func Timeout(t time.Duration) Option

Timeout returns an Option function that sets the timeout value for the Options. The given timeout value will be applied when the returned function is called.

type Options added in v0.19.0

type Options struct {
	Timeout    time.Duration // Timeout specifies the maximum amount of time to wait for an operation to complete.
	MaxRetries uint64        // MaxRetries specifies the maximum number of times to retry the operation in case of failure.
	Capacity   int           // Capacity specifies the maximum number of items that can be processed simultaneously.
}

Options represents configuration for pooling.

type Pool

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

Pool represents a pool of services.

func New

func New(ctx context.Context, options ...Option) *Pool

New a resource pool of the specified capacity Resources are created concurrently to save resource initialization time

func (*Pool) Close added in v0.16.0

func (p *Pool) Close()

Close closes the worker pool, and it is blocked until all workers are idle.

func (*Pool) Closed added in v0.19.0

func (p *Pool) Closed() bool

Closed returns whether the pooling is closed. It uses a select with a timeout of 3 seconds to check if the p.closed channel has been closed.

func (*Pool) Put added in v0.18.0

func (p *Pool) Put(b Bucket)

Put puts wayback requests to the resource pool

func (*Pool) Roll

func (p *Pool) Roll()

Roll process wayback requests from the resource pool for execution.

func (*Pool) Status added in v0.19.0

func (p *Pool) Status() Status

Status returns status of worker pool.

type Status added in v0.19.0

type Status int
const (
	StatusIdle Status = iota
	StatusBusy
)

func (Status) String added in v0.19.0

func (s Status) String() string

String returns description of status.

Jump to

Keyboard shortcuts

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