run

package
v0.0.0-...-c18a219 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: MIT Imports: 8 Imported by: 3

Documentation

Index

Constants

View Source
const PkgPath = "auxo.util.run"

Variables

View Source
var (
	ErrTimeout      = errors.New("timeout")
	ErrPoolShutdown = errors.New("pool is shut down")
	ErrPoolFull     = errors.New("pool reach max queue size")
)

Functions

func Count

func Count(g *sync.WaitGroup, fn func(), r Recovery)

Count call fn with recover, and process WaitGroup automatically.

func Pipeline

func Pipeline(fns ...func() error) error

Pipeline calls all functions in order. If a function returns an error, Pipeline will return this error immediately.

func Safe

func Safe(fn func(), r Recovery)

Safe call fn with recover.

Types

type Canceler

type Canceler interface {
	Cancel()
}

func Schedule

func Schedule(d time.Duration, fn func(), r Recovery) Canceler

Schedule call fn with recover continuously. It returns a Canceler that can be used to cancel the call using its Cancel method.

type Pool

type Pool struct {
	Min, Max int32
	Backlog  int
	Idle     time.Duration
	Debug    bool
	// contains filtered or unexported fields
}

Pool is a simple goroutine pool.

func (*Pool) Put

func (p *Pool) Put(job func()) error

Put submits the job to pool.

func (*Pool) Start

func (p *Pool) Start()

Start start the pool

func (*Pool) Stop

func (p *Pool) Stop()

Stop shuts down the pool. Stop won't interrupt the running jobs.

func (*Pool) Wait

func (p *Pool) Wait(timeout time.Duration) error

Wait waits the running jobs to finish.

type Recovery

type Recovery func(e interface{})

Jump to

Keyboard shortcuts

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