Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Pool ¶
type Pool interface { // Stop stops the worker pool. It does not wait to drain any internal queues, but it does wait for the currently // running tasks to complete. It must only be called once. Stop() // SubmitWithKey submits a function to be executed by the worker pool, ensuring that: // * Only one job with given key can be waiting to be executed at the time. This is desired if we don't want to // run the same task multiple times, e.g. if it's a component update that we only need to run once. // * Only one job with given key can be running at the time. This is desired when we don't want to duplicate work, // and we want to protect the pool from a slow task hogging all the workers. // // Note that it is possible to have two tasks with the same key in the pool at the same time: one waiting to be // executed and another one running. This ensures that a request to re-run a task with the same key is not lost. // // Adding a job with a key that is already queued is a no-op (even if the submitted function is different). // Error is returned if the pool is unable to accept extra work - the caller can decide how to handle this situation. SubmitWithKey(string, func()) error // QueueSize returns the number of tasks currently queued or running. QueueSize() int }
func NewDefaultWorkerPool ¶
func NewDefaultWorkerPool() Pool
func NewFixedWorkerPool ¶ added in v0.38.0
NewFixedWorkerPool creates a new Pool with the given number of workers and given max queue size. The max queue size is the maximum number of tasks that can be queued OR running at the same time. The tasks can run on a random worker, but workQueue ensures only one task with given key is running at a time. The pool is automatically started and ready to accept work. To prevent resource leak, Stop() must be called when the pool is no longer needed.
Click to show internal directories.
Click to hide internal directories.