worker

package
v8.56.1709838579-SHA-e... Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MapQueue

type MapQueue[K comparable, T any] struct {
	// contains filtered or unexported fields
}

A MapQueue is a grouping of multiple queues. Items are sent to a queue determined by the `keyFn`.

func NewMapQueue

func NewMapQueue[K comparable, T any](ctx context.Context, pool Pool, keyFn func(T) K, workFn func(context.Context, T) error) *MapQueue[K, T]

NewMapQueue creates a new map queue that partitions incoming work items based on the provided `keyFn`. If the provided `ctx` is canceled, the entire set of queues will be canceled and pending work items may be lost. Additionally, the standard `errgroup` `pool` implementation will cancel the context if the `workFn` returns a non-nil error, which will also cause pending work items to be lost.

func (*MapQueue[K, T]) Enqueue

func (mq *MapQueue[K, T]) Enqueue(item T) bool

type Pool

type Pool interface {
	Go(func() error)
}

type Queue

type Queue[T any] interface {
	Enqueue(T) bool
}

Queue is something that can enqueue a work item for asynchronous processing.

func NewSerialQueue

func NewSerialQueue[T any](ctx context.Context, pool Pool, workFn func(context.Context, T) error) Queue[T]

NewSerialQueue creates a new serial queue that will handle incoming work items one by one. The single worker is stopped once the provided context is canceled. Depending on the `pool` implementation, if the `workFn` returns a non-nil error the context may be canceled. In both cases, any pending work items are lost.

type SerialQueue

type SerialQueue[T any] struct {
	// contains filtered or unexported fields
}

SerialQueue is an extremely basic Queue implementation that handles incoming work items one by one.

func (*SerialQueue[T]) Enqueue

func (q *SerialQueue[T]) Enqueue(item T) bool

Add the provided `item` to the queue. Returns true if the item was added successfully.

Jump to

Keyboard shortcuts

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