slave

package
v0.0.0-...-a5c5f28 Latest Latest
Warning

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

Go to latest
Published: May 22, 2019 License: Apache-2.0, BSD-2-Clause, BSD-3-Clause, + 1 more Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrSlaveOpened occurs whem the same
	// slave is open twice
	ErrSlaveOpened = errors.New("slave is already opened")
)

Functions

This section is empty.

Types

type Slave

type Slave struct {

	// Name of slave
	Name string
	// Work of slave
	Work func(interface{}) interface{}
	// Function that will be execute when
	// Work finishes. The return value of
	// Work() will be parse to After()
	After func(interface{})
	// contains filtered or unexported fields
}

Slave object that will do the works

func NewSlave

func NewSlave(name string,
	work func(interface{}) interface{},
	after func(interface{})) *Slave

NewSlave Create a slave easily parsing the name of slave, work to do when SendWork it's called (cannot be nil) and work to do after Work() it's called

func (*Slave) Close

func (s *Slave) Close()

Close waits all jobs to finish and close buffered channel of jobs

func (*Slave) Open

func (s *Slave) Open() error

Open Creates job buffered channel and starts a goroutine which will receive all works asynchronously

func (*Slave) SendWork

func (s *Slave) SendWork(job interface{})

SendWork sends work to slave and increment WaitGroup

func (*Slave) ToDo

func (s *Slave) ToDo() int

ToDo Returns the number of jobs to do

Jump to

Keyboard shortcuts

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