concurrent

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2025 License: Apache-2.0 Imports: 5 Imported by: 19

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 MeasuringRunner interface {
	GoRun(doFunc func() (uint64, error)) error
	Reap() error
}

type SimpleRunner added in v0.7.0

type SimpleRunner interface {
	GoRun(doFunc func() error) error
	Reap() error
}

type State

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

State maintains state needed to manage running functions concurrently.

func NewState

func NewState(numConcurrent uint) *State

NewState returns a new State.

func NewStateWithLinearConcurrencyIncrease

func NewStateWithLinearConcurrencyIncrease(initialNumConcurrent uint,
	maximumNumConcurrent uint) *State

func (*State) GoRun

func (state *State) GoRun(doFunc func() error) error

GoRun will run the provided function in a goroutine. 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 (*State) Reap

func (state *State) Reap() error

Reap returns the first error encountered by the functions and waits for remaining functions to complete. The State can no longer be used after Reap.

Jump to

Keyboard shortcuts

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