Documentation
¶
Overview ¶
Package threading provides tools for multi threading applications.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallbackFunc ¶
CallbackFunc describes the interface for a func called before and after running a job.
type EventQueue ¶
type EventQueue struct {
// contains filtered or unexported fields
}
EventQueue is used to divide [Subscriber]s between [Worker]s. This prevents one Worker of being very busy.
func NewEventQueue ¶
func NewEventQueue( logger *slog.Logger, maxWorkers int, channelBufferSize int, ) *EventQueue
NewEventQueue creates a new EventQueue.
func (*EventQueue) AddSubscriber ¶
func (q *EventQueue) AddSubscriber(sub Subscriber)
AddSubscriber adds a Subscriber to the EventQueue.
func (*EventQueue) EnqueueEvent ¶
func (q *EventQueue) EnqueueEvent(event any)
EnqueueEvent puts an event on the Worker channels.
func (*EventQueue) RemoveSubscriber ¶
func (q *EventQueue) RemoveSubscriber(sub Subscriber)
RemoveSubscriber removes a Subscriber from the EventQueue.
type Job ¶
type Job interface {
ID() string
Run(context.Context, *slog.Logger) error
RunEvery() time.Duration
}
Job describes the interface for a job executable by the jobqueue.
type JobQueue ¶
type JobQueue struct {
// contains filtered or unexported fields
}
JobQueue is a queue of Jobs which will be executed by the workerpool.
func NewJobQueue ¶
NewJobQueue creates a new jobqueue.
func (*JobQueue) AddJob ¶
func (q *JobQueue) AddJob(job Job, callback CallbackFunc) error
AddJob adds a recurring job which should be executed by the workerpool. This will also execute the job.
func (*JobQueue) FetchJobIDs ¶
FetchJobIDs fetches all IDs for all jobs.
func (*JobQueue) FetchState ¶
FetchState fetches the current state of the specified job.
type Subscriber ¶
Subscriber describes the interface of subscribers of new events.
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
Worker is used to handle work of the WorkerPool.
func (*Worker) IsDoingWork ¶ added in v0.3.1
IsDoingWork fetches the current state of the worker.
type WorkerPool ¶
type WorkerPool struct {
// contains filtered or unexported fields
}
WorkerPool is used to divide [Subscriber]s between [Worker]s. This prevents one Worker of being very busy.
func NewWorkerPool ¶
func NewWorkerPool( logger *slog.Logger, amountWorkers int, queueSize int, ) *WorkerPool
NewWorkerPool creates a new WorkerPool.
func (*WorkerPool) Active ¶
func (pool *WorkerPool) Active() bool
Active checks if the WorkerPool is active by checking if any Worker is active.
func (*WorkerPool) EnqueueWork ¶
func (pool *WorkerPool) EnqueueWork(doWork DoWork)
EnqueueWork puts an work on the queue.
func (*WorkerPool) IsDoingWork ¶ added in v0.3.1
func (pool *WorkerPool) IsDoingWork() bool
IsDoingWork checks if the WorkerPool is still processing work.
func (*WorkerPool) IsWorkRemaining ¶
func (pool *WorkerPool) IsWorkRemaining() bool
IsWorkRemaining checks if there is still work on the queue.
func (*WorkerPool) Start ¶
func (pool *WorkerPool) Start()
Start starts [Worker]s of a WorkerPool if they weren't active yet.
func (*WorkerPool) WaitUntilDone ¶
func (pool *WorkerPool) WaitUntilDone()
WaitUntilDone blocks until the queue is empty.