workerpool

package module
v0.0.0-...-c84daa6 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 4 Imported by: 0

README

NaiveWorkerPool

Go Report Card

Go package for using a simple and dynamically growing worker pool to submit functions to.

initialWorkerCount := uint64(4)
maxWorker := uint(64)
pool := Create(initialWorkerCount, maxWorker)

pool.Submit(func() {
  // Any work you want to be done. Pool will grow dynamically when too much work is queued up.
})

// Shut down the pool, but wait for all work to be done
pool.Dispose()

A pool can grow until it reaches the specified max worker limit. The pool will stay on that level until all work is done. It will then decrease again until it reaches the initial size. The growing will (naively) starting now when more than 10 functions are queued up.

See GoDoc for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NaiveWorker

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

NaiveWorker is a naive implementation of the Worker interface

type NaiveWorkerPool

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

NaiveWorkerPool provides a naive implementation of the worker pool interface

func Create

func Create(initialSize uint64, maxSize uint64) *NaiveWorkerPool

Create a naive worker pool with the specified initial and max size

func (*NaiveWorkerPool) Dispose

func (nwp *NaiveWorkerPool) Dispose()

Dispose shuts down the worker pool, but waits for all work to finish

func (*NaiveWorkerPool) IsDisposed

func (nwp *NaiveWorkerPool) IsDisposed() bool

IsDisposed checks if the pool has been disposed

func (*NaiveWorkerPool) IsDisposing

func (nwp *NaiveWorkerPool) IsDisposing() bool

IsDisposing checks if the pool is currently disposing/shutting down

func (*NaiveWorkerPool) Submit

func (nwp *NaiveWorkerPool) Submit(workerFunc func())

Submit work to the worker pool. Work will not be submitted if the pool is shutting down or shut down.

type Worker

type Worker interface {
	// contains filtered or unexported methods
}

Worker provides a standard worker interface for the worker pool

type WorkerPool

type WorkerPool interface {
	Submit(work func())
	Dispose()
	IsDisposing() bool
	IsDisposed() bool
	// contains filtered or unexported methods
}

WorkerPool is a simple thread safe worker pool

Jump to

Keyboard shortcuts

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