async

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Group added in v1.1.0

func Group[T any](size int, handlerFunc HandlerFunc[T], tags ...string) *group[T]

Builds a new group for the given tags and specified number of concurrent jobs allowed.

Types

type HandlerFunc added in v1.1.0

type HandlerFunc[T any] func(context.Context, T) error

type NameFunc added in v1.1.0

type NameFunc[T any] func(T) string

type PollingFunc added in v1.1.0

type PollingFunc[T any] func(context.Context, []string) ([]T, error)

type Pool added in v1.1.0

type Pool interface {
	Start() // Start the pool and all its workers (must be called in a goroutine)
	Stop()  // Wait for the current pool to complete and returns
}

Generic interface for an async worker which can be started and stopped.

func NewPool added in v1.1.0

func NewPool[T any](
	logger log.Logger,
	interval time.Duration,
	pollingFunc PollingFunc[T],
	nameFunc NameFunc[T],
	groups ...*group[T],
) Pool

Builds a new pool which will call the given handler func at the specified interval. The handler will be called for each group of jobs which have not reached their capacity and it will received the group tags as argument so that you can filter the job being returned.

The idea behind pool groups is that some jobs need more time to complete and I don't want to hold back the other ones such as (in the future), sending emails, checking stuff, etc.

Jump to

Keyboard shortcuts

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