concurrency

package
v0.0.0-...-d271c08 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2014 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllErrorAggregator

type AllErrorAggregator func(errors []error) error

type AllErrorRecorder

type AllErrorRecorder struct {
	Errors []error
	// contains filtered or unexported fields
}

AllErrorRecorder records all the errors.

func (*AllErrorRecorder) AggrError

func (aer *AllErrorRecorder) AggrError(aggr AllErrorAggregator) error

AggrError() runs the provided aggregator over all errors and returns the error from aggregator.

func (*AllErrorRecorder) Error

func (aer *AllErrorRecorder) Error() error

Error() returns an aggregate of all errors by concatenation.

func (*AllErrorRecorder) ErrorStrings

func (aer *AllErrorRecorder) ErrorStrings() []string

ErrorStrings() returns all errors as string array.

func (*AllErrorRecorder) HasErrors

func (aer *AllErrorRecorder) HasErrors() bool

HasErrors returns true if we ever recorded an error

func (*AllErrorRecorder) RecordError

func (aer *AllErrorRecorder) RecordError(err error)

RecordError records a possible error: - does nothing if err is nil

type ErrorRecorder

type ErrorRecorder interface {
	RecordError(error)
	HasErrors() bool
	Error() error
}

ErrorRecorder offers a way to record errors during complex asynchronous operations. Various implementation will offer different services.

type FirstErrorRecorder

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

FirstErrorRecorder records the first error, logs the others. Error() will return the first recorded error or nil.

func (*FirstErrorRecorder) Error

func (fer *FirstErrorRecorder) Error() error

Error returns the first error we saw, or nil

func (*FirstErrorRecorder) HasErrors

func (fer *FirstErrorRecorder) HasErrors() bool

HasErrors returns true if we ever recorded an error

func (*FirstErrorRecorder) RecordError

func (fer *FirstErrorRecorder) RecordError(err error)

RecordError records a possible error: - does nothing if err is nil - only records the first error reported - the rest is just logged

type MultiResourceConstraint

type MultiResourceConstraint struct {
	FirstErrorRecorder
	// contains filtered or unexported fields
}

MultiResourceConstraint combines 3 different features: - a WaitGroup to wait for all tasks to be done - a Semaphore map to control multiple concurrencies - an ErrorRecorder

func NewMultiResourceConstraint

func NewMultiResourceConstraint(semaphoreMap map[string]*sync2.Semaphore) *MultiResourceConstraint

func (*MultiResourceConstraint) Acquire

func (mrc *MultiResourceConstraint) Acquire(name string)

Acquire will wait until we have a resource to use

func (*MultiResourceConstraint) Add

func (mrc *MultiResourceConstraint) Add(n int)

func (*MultiResourceConstraint) Done

func (mrc *MultiResourceConstraint) Done()

func (*MultiResourceConstraint) Release

func (mrc *MultiResourceConstraint) Release(name string)

func (*MultiResourceConstraint) ReleaseAndDone

func (mrc *MultiResourceConstraint) ReleaseAndDone(name string)

func (*MultiResourceConstraint) Wait

func (mrc *MultiResourceConstraint) Wait() error

Returns the firstError we encountered, or nil

type ResourceConstraint

type ResourceConstraint struct {
	FirstErrorRecorder
	// contains filtered or unexported fields
}

ResourceConstraint combines 3 different features: - a WaitGroup to wait for all tasks to be done - a Semaphore to control concurrency - an ErrorRecorder

func NewResourceConstraint

func NewResourceConstraint(max int) *ResourceConstraint

NewResourceConstraint creates a ResourceConstraint with max concurrency.

func (*ResourceConstraint) Acquire

func (rc *ResourceConstraint) Acquire()

Acquire will wait until we have a resource to use

func (*ResourceConstraint) Add

func (rc *ResourceConstraint) Add(n int)

func (*ResourceConstraint) Done

func (rc *ResourceConstraint) Done()

func (*ResourceConstraint) Release

func (rc *ResourceConstraint) Release()

func (*ResourceConstraint) ReleaseAndDone

func (rc *ResourceConstraint) ReleaseAndDone()

func (*ResourceConstraint) Wait

func (rc *ResourceConstraint) Wait() error

Wait waits for the WG and returns the firstError we encountered, or nil

Jump to

Keyboard shortcuts

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