workerpool

package
v3.29.2 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Component

type Component interface {
	task.Starter
	FromRequestContext(context.Context) context.Context
}

Component contains a minimal component.Component definition.

type Config

type Config[T any] struct {
	Component
	context.Context                 // The base context of the pool.
	Name              string        // The name of the pool.
	Handler           Handler[T]    // The work handler.
	MinWorkers        int           // The minimum number of workers in the pool. Use -1 to disable.
	MaxWorkers        int           // The maximum number of workers in the pool.
	QueueSize         int           // The size of the work queue. Use -1 to disable.
	WorkerIdleTimeout time.Duration // The maximum amount of time a worker will stay idle before closing.
}

Config is the configuration of the worker pool.

type Handler

type Handler[T any] func(ctx context.Context, item T)

Handler is a function that processes items published to the worker pool.

func HandlerFromUplinkHandler added in v3.15.1

func HandlerFromUplinkHandler(
	handler func(context.Context, *ttnpb.ApplicationUp) error,
) Handler[*ttnpb.ApplicationUp]

HandlerFromUplinkHandler converts a static uplink handler to a Handler.

type WorkerPool

type WorkerPool[T any] interface {
	// Publish publishes an item to the worker pool to be processed.
	// Publish may spawn a worker in order to fullfil the work load.
	// Publish does not block.
	Publish(ctx context.Context, item T) error

	// Wait blocks until all workers have been closed.
	Wait()
}

WorkerPool is a dynamic pool of workers to which work items can be published. The workers are created on demand and live as long as work is available.

func NewWorkerPool

func NewWorkerPool[T any](cfg Config[T]) WorkerPool[T]

NewWorkerPool creates a new WorkerPool with the provided configuration.

Jump to

Keyboard shortcuts

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