grpool

package
v0.0.0-...-a516d7c Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2021 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(timeout time.Duration, fn func() (interface{}, error)) (result interface{}, timedOut bool, err error)

Types

type Job

type Job struct {
	Jobid   interface{}
	Jobfunc func() (interface{}, error)
}

Represents user request, function which should be executed in some worker.

type Jobresult

type Jobresult struct {
	Jobid    interface{}
	Timedout bool
	Result   interface{}
	Err      error
}

type Pool

type Pool struct {
	JobQueue chan Job

	Jobresult chan Jobresult
	// contains filtered or unexported fields
}

func NewPool

func NewPool(numWorkers int, jobQueueLen int, timeout time.Duration) *Pool

Will make pool of gorouting workers. numWorkers - how many workers will be created for this pool queueLen - how many jobs can we accept until we block

Returned object contains JobQueue reference, which you can use to send job to pool.

func (*Pool) JobDone

func (p *Pool) JobDone()

In case you are using WaitAll fn, you should call this method every time your job is done.

If you are not using WaitAll then we assume you have your own way of synchronizing.

func (*Pool) Release

func (p *Pool) Release()

Will release resources used by pool

func (*Pool) WaitAll

func (p *Pool) WaitAll()

Will wait for all jobs to finish.

func (*Pool) WaitCount

func (p *Pool) WaitCount(count int)

How many jobs we should wait when calling WaitAll. It is using WaitGroup Add/Done/Wait

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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