Documentation ¶
Overview ¶
Package limited provides a groutine execution Pool that spins a goroutine per Submit() but is hard limited to the number of goroutines that can run at any time.
As Go has matured, goroutines have become more efficient. This type of pool starts very fast and is only slightly slower than our pooled version. For pools that you want to start up and tear down quickly, this might be the best choice.
See the examples in the parent package "goroutines" for an overview of using pools.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Caller ¶
func Caller(name string) goroutines.SubmitOption
Caller sets the name of the calling function so that metrics can differentiate who is using the goroutines in the pool. With the introduction of generics, there is no way to get the name of function call reliably, as generic functions are written dynamically and runtime.FuncForPC does not work for generics. If this is not set, we will use runtime.FuncForPC().
func NonBlocking ¶
func NonBlocking() goroutines.SubmitOption
NonBlocking indicates that if we are at our limit, we still run the goroutine and it is not counted against the total. This is useful when you want to track the statistics still but need this goroutine to run and don't want to do it naked.
Types ¶
type Pool ¶
type Pool struct { pool.Pool // Implements the pool.Preventer interface // contains filtered or unexported fields }
Pool is a pool of goroutines.
func New ¶
New creates a new Pool. "name" is the name of the pool which is used to get OTEL metrics and traces. These names must be globally unique, so it is best to set it to the package path + pool name that is using it. However, if not unique, a unique name will be created. If name is the empty string, the pool will not be registered, which is useful if creating and tearing down the pool instead of using it for the lifetime of the program. Names cannot contain spaces, hyphens, or numbers. "size" is the number of goroutines that can execute concurrently.
func (*Pool) Close ¶
func (p *Pool) Close()
Close waits for all submitted jobs to stop, then stops all goroutines.
func (*Pool) Submit ¶
func (p *Pool) Submit(ctx context.Context, runner goroutines.Job, options ...goroutines.SubmitOption) error
Submit submits the runner to be executed.