worker

package
v0.37.4 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

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

func NewShardedWorkerPool(workersCount int, queueSize int) Pool

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.

Jump to

Keyboard shortcuts

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