Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrAlreadyStarted = errors.New("already_started")
Functions ¶
This section is empty.
Types ¶
type Group ¶ added in v1.1.0
type Group[T any] interface { OnStart(PoolContext[T]) // Called upon pool startup, use PoolContext.Run to register a goroutine Handle(context.Context, T) bool // Try to handle the given job, returns true if the job was handled, false otherwise }
Async group of runners which can actually handle jobs.
func GroupFunc ¶ added in v1.2.0
func GroupFunc[T any](size int, handlerFunc HandlerFunc[T], canHandle SelectorFunc[T]) Group[T]
Builds a new runners group which will process jobs satisfying the canHandle function.
type HandlerFunc ¶ added in v1.1.0
type Pool ¶ added in v1.1.0
type Pool[T any] interface { Start() error // Start the pool Stop() // Wait for the current pool to complete running jobs and returns }
Represents an asynchronous pool which can process multiple jobs simultaneously.
func NewPool ¶ added in v1.1.0
Builds a new pool with a specific Puller to feed registered groups with actual jobs to process.
The idea behind 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.
type PoolContext ¶ added in v1.2.0
type PoolContext[T any] interface { Queue(context.Context, ...T) // Queue one or multiple jobs to be processed Logger() log.Logger // Returns the logger used by the pool Run(Func) // Launch a function in a new goroutine which MUST listen for the done signal and exit when it receives it }
Pool context as seen by puller, groups and internal stuff.
type Puller ¶ added in v1.2.0
type Puller[T any] interface { OnStart(PoolContext[T]) // Called upon pool startup, use PoolContext.Run to register a goroutine }
Puller interface used to retrieve jobs to process from somewhere.
Click to show internal directories.
Click to hide internal directories.