Documentation ¶
Overview ¶
Package pooled provides a Pool of goroutines where you can submit Jobs to be run when by an exisiting goroutine instead of spinning off a new goroutine.
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 a pooled goroutine is not available, spin off a goroutine and do not block.
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.