cuba

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2019 License: MIT Imports: 5 Imported by: 12

README

Project Cuba

Experiment in allowing workers to own the means of production.

Go's built in chans are based on the Communicating Sequential Processes (CSP) model. They work well when the processing is sequential, i.e.

Producer -> Processor [-> Processor ...] -> Consumer

But not everything fits well with this model, like when work is discovered as part of the processing. Examples are walking a directory structure, and finding more subdirectories as you go -- or a web crawler following hyperlinks from the pages it crawls.

Cuba attempts to build a parallel system where processes can both consume and produce work simultaneously.

Documentation

Index

Constants

View Source
const (
	POOL_RUN = iota
	POOL_FINISH
	POOL_ABORT
)

Variables

View Source
var PoolAbortedErr = errors.New("pool has been aborted")

Functions

This section is empty.

Types

type Bucket added in v0.2.0

type Bucket interface {
	Push(interface{})
	PushAll([]interface{})
	Pop() interface{}
	IsEmpty() bool
	Empty()
}

type Handle added in v0.2.0

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

func (*Handle) Item added in v0.2.0

func (handle *Handle) Item() interface{}

func (*Handle) Push added in v0.2.0

func (handle *Handle) Push(item interface{})

func (*Handle) Sync added in v0.2.0

func (handle *Handle) Sync()

type Pool added in v0.2.0

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

func New added in v0.2.0

func New(task Task, bucket Bucket) *Pool

Constructs a new Cuba thread pool.

The worker callback will be called by multiple goroutines in parallel, so is expected to be thread safe.

Bucket affects the order that items will be processed in. cuba.NewQueue() provides FIFO ordering, while cuba.NewStack() provides LIFO ordered work.

func (*Pool) Abort added in v0.3.0

func (pool *Pool) Abort()

func (*Pool) Finish added in v0.2.0

func (pool *Pool) Finish()

Calling Finish() waits for all work to complete, and allows goroutines to shut down.

func (*Pool) Push added in v0.2.0

func (pool *Pool) Push(item interface{}) error

Push an item into the worker pool. This will be scheduled to run on a worker immediately.

func (*Pool) PushAll added in v0.2.0

func (pool *Pool) PushAll(items []interface{}) error

Push multiple items into the worker pool.

Compared to Push() this only aquires the lock once, so may reduce lock contention.

func (*Pool) SetMaxWorkers added in v0.2.0

func (pool *Pool) SetMaxWorkers(n int32)

Sets the maximum number of worker goroutines.

Default: runtime.NumCPU() (i.e. the number of CPU cores available)

type Queue added in v0.2.0

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

func NewQueue added in v0.2.0

func NewQueue() *Queue

func (*Queue) Empty added in v0.2.0

func (queue *Queue) Empty()

func (*Queue) IsEmpty added in v0.3.0

func (queue *Queue) IsEmpty() bool

func (*Queue) Pop added in v0.2.0

func (queue *Queue) Pop() interface{}

func (*Queue) Push added in v0.2.0

func (queue *Queue) Push(item interface{})

func (*Queue) PushAll added in v0.2.0

func (queue *Queue) PushAll(items []interface{})

type Stack added in v0.2.0

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

func NewStack

func NewStack() *Stack

func (*Stack) Empty added in v0.2.0

func (stack *Stack) Empty()

func (*Stack) IsEmpty added in v0.3.0

func (stack *Stack) IsEmpty() bool

func (*Stack) Pop added in v0.2.0

func (stack *Stack) Pop() interface{}

func (*Stack) Push added in v0.2.0

func (stack *Stack) Push(item interface{})

func (*Stack) PushAll added in v0.2.0

func (stack *Stack) PushAll(items []interface{})

type Task added in v0.2.0

type Task func(*Handle)

Directories

Path Synopsis
examples
abort command
dirwalk command
simple command

Jump to

Keyboard shortcuts

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