chalk

package module
v0.0.0-...-1ad7fab Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2015 License: MIT Imports: 1 Imported by: 0

README

Chalk Build Status Godoc license

Quickly and easily create a pool of go routines. Create as many "queues" as you want, each with their own number of go routines ready to do your bidding.

Installation

$ go get https://github.com/markbates/chalk

Usage

// create a pool of 10 go routines
c := chalk.New(10)

c.Tasks <- func() error {
  // do some work here
  return nil
}

// handle err
c.Tasks <- func() error {
  return errors.New("boom!")
}

err := <-c.Errors

// wait for all of the workers to finish
c.Wait()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Chalk

type Chalk struct {
	*sync.WaitGroup
	// Tasks channel receives `Task` functions and
	// adds them to the pool.
	Tasks chan Task
	// Errors handles communication of errors that may
	// occur when running a `Task` in the pool.
	Errors chan error
}

Chalk wraps the `sync.WaitGroup` and the channels used to add tasks to the pool and return errors for the tasks in the pool.

func New

func New(size int) *Chalk

New creates a new pool N go routines. It will return two channels. The first channel is used to send `Task` functions to the pool to be executed. The second channel can be used to listen for any errors that may occur during the processing of a `Task`.

func (*Chalk) Wait

func (c *Chalk) Wait()

Wait will close the `c.Tasks` channel and then wait for all of the tasks in the pool to finish. This is a *blocking* operation.

type Task

type Task func() error

Task is the definition of the function that will be sent to the pool of go routines

Jump to

Keyboard shortcuts

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