worker

package
v0.0.0-...-471d277 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2022 License: Apache-2.0 Imports: 2 Imported by: 6

Documentation

Overview

Example
var totalCounter int32
pool := Pool{
	MaxWorkers: 1,
	Op: func(req Request) error {
		atomic.AddInt32(&totalCounter, 1)
		return nil
	},
}

pool.Initialize()
for counter := 0; counter < 5; counter++ {
	pool.AddWork(TestRequest{})
}
// Poll is not usable after calling Join
if err := pool.Join(); err != nil {
	log.Fatal(err)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

type Pool struct {
	MaxWorkers int
	Op         func(Request) error
	// contains filtered or unexported fields
}

Pool is a wrapper to manage a set of Workers efficiently

func (*Pool) ActiveCount

func (pool *Pool) ActiveCount() int

ActiveCount is the count of the workers who are active and doing work

func (*Pool) AddWork

func (pool *Pool) AddWork(work Request)

AddWork to a worker in the Pool

func (*Pool) Count

func (pool *Pool) Count() int

Count returns the sum of Pending() + ActiveCount()

func (*Pool) Initialize

func (pool *Pool) Initialize()

Initialize the pool

func (*Pool) Join

func (pool *Pool) Join() error

Join waits for all the tasks to complete - pool is not usable after this

func (*Pool) Pending

func (pool *Pool) Pending() int

Pending returns the number of items still pending to be processed

func (*Pool) Wait

func (pool *Pool) Wait() error

Wait similar to Join, but the pool is still usable after this

type Request

type Request interface{}

Request Base type of all work objects

type Worker

type Worker struct {
	Queue  chan Request
	Errs   chan error
	Op     func(Request) error
	Marker *sync.CountWG
}

Worker for now

func (*Worker) Start

func (w *Worker) Start()

Start a worker

Jump to

Keyboard shortcuts

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