workers

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 14, 2020 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Pool

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

Pool represents a pool of multiple managed workers.

func NewPool

func NewPool(size int) (*Pool, error)

NewPool returns a new worker pool.

func (*Pool) Close

func (p *Pool) Close() error

Close closes the pool and stops all associated goroutines.

func (*Pool) Queue

func (p *Pool) Queue(t Task) error

Queue queues a task on a pools queue.

func (*Pool) Start

func (p *Pool) Start() error

Start starts a pool. This includes one goroutine for each worker and one for the queue.

type Task

type Task struct {
	Fn     func(params []interface{})
	Params []interface{}
}

Task represents the combination of a function and parameters to be executed by a worker. You should use type casting in your Task function to use the parameters. Example of this:

Task{
	Fn: func(params []interface{}) {
		var (
			n1 = params[0].(int)
			n2 = params[1].(int)
		)

		fmt.Printf("Sum: %d", n1+n2)
	},
	Params: []interface{}{5, 5}
}

Jump to

Keyboard shortcuts

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