Documentation
¶
Overview ¶
Package concurrent provides a simple way to run functions concurrently and then reap the results.
Package concurrent allows cuncurrent running of provided functions, by default limiting the parallelism to the number of CPUs. The functions return an error value and these may be reaped at the end.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoScaler ¶ added in v0.7.0
type AutoScaler struct {
// contains filtered or unexported fields
}
func NewAutoScaler ¶ added in v0.7.0
func NewAutoScaler(maxConcurrent uint) *AutoScaler
NewAutoScaler returns a new AutoScaler state which can be used to run goroutines concurrently, adjusting the number of goroutines until peak throughput is acheived. The maximum number of goroutines is specified by maxConcurrent (runtime.NumCPU() if zero). If maxConcurrent is 1 then no goroutines are created and work is performed synchronously.
func (*AutoScaler) GoRun ¶ added in v0.7.0
func (state *AutoScaler) GoRun(doFunc func() (uint64, error)) error
GoRun will run the provided function in a goroutine. It must return a value indicating the amount of work done (used in estimating throughput) and an error. If the function returns a non-nil error, this will be returned in a future call to GoRun or by Reap. GoRun cannot be called concurrently with GoRun or Reap.
func (*AutoScaler) Reap ¶ added in v0.7.0
func (state *AutoScaler) Reap() error
Reap returns the first error encountered by the functions and waits for remaining functions to complete. The AutoScaler can no longer be used after Reap.
type MeasuringRunner ¶ added in v0.7.0
type SimpleRunner ¶ added in v0.7.0
type State ¶
type State struct {
// contains filtered or unexported fields
}
State maintains state needed to manage running functions concurrently.