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() // Submit submits a function to be executed by the worker pool on a random worker. Error is returned if the pool // is unable to accept extra work. Submit(func()) error // SubmitWithKey submits a function to be executed by the worker pool, ensuring that only one // job with given key can be queued at the time. 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. QueueSize() int }
func NewDefaultWorkerPool ¶
func NewDefaultWorkerPool() Pool
func NewShardedWorkerPool ¶
NewShardedWorkerPool creates a new worker pool with the given number of workers and queue size for each worker. The queued tasks are sharded across the workers using a hash of the key. 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.