pooling

package
v0.18.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 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 Pool

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

Pool represents a pool of services.

func New

func New(ctx context.Context, capacity int) *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) Put added in v0.18.0

func (p *Pool) Put(b Bucket)

Pub puts wayback requests to the resource pool

func (*Pool) Roll

func (p *Pool) Roll()

Roll process wayback requests from the resource pool for execution.

// Stream generates values with DoSomething and sends them to out
// until DoSomething returns an error or ctx.Done is closed.
func Stream(ctx context.Context, out chan<- Value) error {
	for {
		v, err := DoSomething(ctx)
		if err != nil {
			return err
		}
		select {
		case <-ctx.Done():
			return ctx.Err()
		case out <- v:
		}
	}
}

Jump to

Keyboard shortcuts

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