Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithMaxQueueSize ¶
WithMaxQueueSize is an ExecutorOption for the TimedExecutor that allows to specify a maxSize of the underlying queue.
Types ¶
type Executor ¶
type Executor struct {
// contains filtered or unexported fields
}
Executor defines a scheduler that executes tasks in the background at a given time. It does not spawn any additional goroutines for each task and executes the tasks sequentially (in each worker).
func NewExecutor ¶
NewExecutor is the constructor for a timed Executor that creates a scheduler with a given number of workers that execute the scheduled tasks in parallel (whenever they become due).
func (*Executor) ExecuteAfter ¶
func (t *Executor) ExecuteAfter(f func(), delay time.Duration) *ScheduledTask
ExecuteAfter executes the given function after the given delay.
func (*Executor) ExecuteAt ¶
func (t *Executor) ExecuteAt(f func(), time time.Time) *ScheduledTask
ExecuteAt executes the given function at the given time.
func (*Executor) Shutdown ¶
func (t *Executor) Shutdown(optionalShutdownFlags ...ShutdownFlag)
Shutdown shuts down the TimedExecutor and waits until the executor has shutdown gracefully.
func (*Executor) WorkerCount ¶
WorkerCount returns the amount of background workers that this executor uses.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
Queue represents a queue, that holds values that will only be released at a given time. The corresponding Poll method waits for the element to be available before it returns its value and is therefore blocking.
func (*Queue) Add ¶
func (t *Queue) Add(value any, scheduledTime time.Time) (addedElement *QueueElement)
Add inserts a new element into the queue that can be retrieved via Poll() at the specified time.
func (*Queue) IsShutdown ¶
IsShutdown returns true if this queue was shutdown.
func (*Queue) Poll ¶
Poll returns the first value of this queue. It waits for the scheduled time before returning and is therefore blocking. It returns nil if the queue is empty.
func (*Queue) Shutdown ¶
func (t *Queue) Shutdown(optionalShutdownFlags ...ShutdownFlag)
Shutdown terminates the queue. It accepts an optional list of shutdown flags that allows the caller to modify the shutdown behavior.
type QueueElement ¶
type QueueElement struct { // Value represents the value of the queued element. Value any // contains filtered or unexported fields }
QueueElement is an element in the TimedQueue. It.
func (*QueueElement) Cancel ¶
func (timedQueueElement *QueueElement) Cancel()
Cancel removed the given element from the queue and cancels its execution.
type ShutdownFlag ¶
ShutdownFlag defines the type of the optional shutdown flags.
const ( // CancelPendingElements defines a shutdown flag, that causes the queue to be emptied on shutdown. CancelPendingElements ShutdownFlag = 1 << iota // IgnorePendingTimeouts defines a shutdown flag, that makes the queue ignore the timeouts of the remaining queued // elements. Consecutive calls to Poll will immediately return these elements. IgnorePendingTimeouts // PanicOnModificationsAfterShutdown makes the queue panic instead of ignoring consecutive writes or modifications. PanicOnModificationsAfterShutdown // DontWaitForShutdown causes the TimedExecutor to not wait for all tasks to be executed before returning from the // Shutdown method. DontWaitForShutdown ShutdownFlag = 1 << 7 )
type TaskExecutor ¶
type TaskExecutor[T comparable] struct { *Executor // contains filtered or unexported fields }
TaskExecutor is a TimedExecutor that internally manages the scheduled callbacks as tasks with a unique identifier. It allows to replace existing scheduled tasks and cancel them using the same identifier.
func NewTaskExecutor ¶
func NewTaskExecutor[T comparable](workerCount int) *TaskExecutor[T]
NewTaskExecutor is the constructor of the TaskExecutor.
func (*TaskExecutor[T]) Cancel ¶
func (t *TaskExecutor[T]) Cancel(identifier T) (canceled bool)
Cancel cancels a queued task.
func (*TaskExecutor[T]) ExecuteAfter ¶
func (t *TaskExecutor[T]) ExecuteAfter(identifier T, callback func(), delay time.Duration) *ScheduledTask
ExecuteAfter executes the given function after the given delay.
func (*TaskExecutor[T]) ExecuteAt ¶
func (t *TaskExecutor[T]) ExecuteAt(identifier T, callback func(), executionTime time.Time) *ScheduledTask
ExecuteAt executes the given function at the given time.