task

package
v0.0.50-alpha.82 Latest Latest
Warning

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

Go to latest
Published: May 16, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Least strategy = iota + 1
)

Variables

View Source
var (
	ErrGlobalQueueFull     = errors.New("global Queue is full")
	ErrWaitingQueueFull    = errors.New("waiting Queue is full")
	ErrProcessingQueueFull = errors.New("processing Queue is full")
	ErrDataNotFound        = errors.New("data not found")
)

Functions

func LeastTask

func LeastTask[T any, K comparable](tm *QueueManager[T, K]) (K, bool)

LeastTask : return key witch has the least tasks

Types

type Options

type Options[T any, K comparable] func(*QueueManager[T, K])

func WithAfterProcessPushFunc

func WithAfterProcessPushFunc[T any, K comparable](fs ...func(key K, data T)) Options[T, K]

func WithStrategy

func WithStrategy[T any, K comparable](s strategy) Options[T, K]

type Queue

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

Queue will pop data from its waiting Queue. If it`s empty, it will pop data from global Queue(in QueueManager), and then push to process Queue.

type QueueManager

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

func NewQueueManager

func NewQueueManager[T any, K comparable](
	maxGlobal, maxProcessing, maxWaiting int,
	equalFunc func(a, b T) bool,
	opts ...Options[T, K],
) *QueueManager[T, K]

func (*QueueManager[T, K]) Delete

func (tm *QueueManager[T, K]) Delete(key K, data T) error

Delete will delete a data in key queues. If delete a data in processing Queue, taskQueue will pop data from its waiting Queue. If it`s empty, it will pop data from global Queue, and then push to process Queue.

func (*QueueManager[T, K]) GetProcessingQueueLengths

func (tm *QueueManager[T, K]) GetProcessingQueueLengths() map[K]int

func (*QueueManager[T, K]) Insert

func (tm *QueueManager[T, K]) Insert(data T) error

func (*QueueManager[T, K]) InsertByKey

func (tm *QueueManager[T, K]) InsertByKey(key K, data T) error

Jump to

Keyboard shortcuts

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