parallel

package module
v0.0.0-...-4de9ce6 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2016 License: BSD-2-Clause Imports: 2 Imported by: 34

Documentation

Overview

Package parallel can be used for easily running goroutines with a limit on concurrency. It also helps with collecting errors.

It is intended as a replacement for github.com/rogpeppe/rog-go/parallel and avoids messing up CPU and memory profiles by not adding its own stack frame.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Errors

type Errors []error

Errors holds any errors encountered during the parallel run.

func (Errors) Error

func (errs Errors) Error() string

type Run

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

Run represents a number of functions running concurrently.

func NewRun

func NewRun(maxPar int) *Run

NewRun returns a new parallel instance. It will allow up to maxPar locks concurrently.

func (*Run) Acquire

func (r *Run) Acquire()

Acquire acquires a lock. Up to maxPar (see NewRun) locks can be held concurrently. If no lock is available, Acquire blocks until another goroutine calls Release.

Caution: Call this before starting a new goroutine, not inside of it (race condition with Wait).

func (*Run) Error

func (r *Run) Error(err error)

Error stores an error to be returned by Wait.

func (*Run) Release

func (r *Run) Release()

Release releases a lock and allows another lock to be aquired by Acquire.

func (*Run) Wait

func (r *Run) Wait() error

Wait waits for all locks to be released. If any errors were encountered, it returns an Errors value describing all the errors in arbitrary order.

Jump to

Keyboard shortcuts

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