Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ParallelQueue ¶
ParallelQueue executes parallel tasks on separate goroutines.
func NewParallelQueue ¶
func NewParallelQueue[T fmt.Stringer](opts ...QueueOption) *ParallelQueue[T]
NewParallelQueue returns a new queue instance.
func (*ParallelQueue[T]) Add ¶
func (q *ParallelQueue[T]) Add(item T) bool
Add an item to the queue. This method is thread safe within op() and can be called during Run(). It is NOT safe to call Add() from a different, unassociated thread. This method returns False when queue state is done.
Calling Add(item) from the op() given to Run() guarantees that item will be processed.
func (*ParallelQueue[T]) Run ¶
Run the queue using op() to process each task. Different op()s must not have interdependencies (e.g. op1 is blocked on op2 completing), as this can result in a deadlock.
Queue execution will stop if op() returns an error or the context is canceled. When an error occurs, goroutines may continue to execute. Use q.WaitForOrphans() to wait for the remaining goroutines.
func (*ParallelQueue[T]) WaitForOrphans ¶
func (q *ParallelQueue[T]) WaitForOrphans(ctx context.Context) error
WaitForOrphans will block until remaining op() goroutines finish. Call this if Run() returns an error and you need to know that all remaining threads of execution are done.
WaitForOrphans will exit early if ctx is cancelled. This `ctx` should be different from the `ctx` given to Run().
type Queue ¶
type Queue[N any] struct { // contains filtered or unexported fields }
Queue for implementing graph algorithms.
type QueueOption ¶
type QueueOption func(*config)
func UseTracer ¶
func UseTracer(t Tracer) QueueOption
func WorkerCount ¶
func WorkerCount(n int) QueueOption
type RunInfo ¶
type RunInfo struct { // ID for the execution. This is item.String(). ID string // Queued is the timestamp of when the task was Add()ed. Queued time.Time // Start is the timestamp of when the task was started as a goroutine. Start time.Time // End is when the task was finished. End time.Time // Err is the result of the task. Err error }
RunInfo records the details of a task.