Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type PriorityQueue ¶
type PriorityQueue[T IPQItem] struct { // contains filtered or unexported fields }
func NewPriorityQueue ¶
func NewPriorityQueue[T IPQItem]() *PriorityQueue[T]
func (*PriorityQueue[T]) Items ¶
func (p *PriorityQueue[T]) Items() []T
func (*PriorityQueue[T]) Len ¶
func (p *PriorityQueue[T]) Len() int
func (*PriorityQueue[T]) Pop ¶
func (p *PriorityQueue[T]) Pop() T
func (*PriorityQueue[T]) Push ¶
func (p *PriorityQueue[T]) Push(item T)
type TaskRunner ¶
type TaskRunner[T ITask] struct { // contains filtered or unexported fields }
TaskRunner ...
Whenever we call "WithPriority(...)" a new task will be pushed in the "pushCh" channel and then the code will block until the task can actually be executed.
The task runner starts 2 threads.
- One that receive new tasks from the "WithPriority" function and put them in the priority queue. It then notifies the "popCh" that a new task has been added.
- The second thread pop tasks from the PQ. Then notify the task that it can be processed. This will unblock the code at "WithPriority", then it waits until that task is done being processed. When the task is completed, it will wait for another one from the "popCh".
This way we can ensure that we ever only have 1 task being executed at the time, but we can queue as many as we want with different priorities.
func NewTaskRunner ¶
func NewTaskRunner[T ITask](ctx context.Context, factory func() T) *TaskRunner[T]
func (*TaskRunner[T]) GetTasks ¶
func (r *TaskRunner[T]) GetTasks() (out TasksOverview)
func (*TaskRunner[T]) WithPriority ¶
func (r *TaskRunner[T]) WithPriority(priority Priority) T
Click to show internal directories.
Click to hide internal directories.