Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BatchParallelize ¶
BatchParallelize splits items into batches of at most width elements, submits each chunk as a single job to q, and returns an iterator that yields the results in order, flattened across batches.
Types ¶
type Comparable ¶
Comparable implements Comparer for an cmp.Ordered value.
type PriorityQueue ¶
A priority queue implemented as a min-heap, a binary tree encoded in a slice.
- Element at index i has children at 2i+1 and 2i+2
- Element at index i has parent at (i-1)/2
- Index 0 is the root (the minimum)
type WorkBatch ¶
type WorkBatch[V any] struct { // contains filtered or unexported fields }
A WorkBatch is a set of jobs submitted to a WorkQueue whose results can be collected in submission order. A Batch must not be copied after first use.
func NewWorkBatch ¶
NewWorkBatch creates a new WorkBatch that submits jobs to q.
func (*WorkBatch[V]) Drain ¶
Drain iterates job results in submission order, blocking until Seal is called and all submitted jobs have finished. If a job panicked, the panic is re-raised at its ordered position.
Seal must be called concurrently with Drain. Calling Seal before Drain works only if total submissions do not exceed the queue width, and will deadlock otherwise; prefer always calling them concurrently.
func (*WorkBatch[V]) Seal ¶
func (b *WorkBatch[V]) Seal()
Seal signals that no more jobs will be submitted, then blocks until all submitted jobs have finished and closes the result channel.
func (*WorkBatch[V]) Submit ¶
func (b *WorkBatch[V]) Submit(fn func() V)
Submit enqueues fn for execution. It blocks until a concurrency slot is available. Panics if called after Seal. Panics in the passed function are forwarded to WorkBatch.Drain.
type WorkQueue ¶
type WorkQueue struct {
// contains filtered or unexported fields
}
WorkQueue is a shared concurrency limiter. Multiple batches may submit jobs to the same queue simultaneously; the total number of concurrently running jobs across all batches is bounded by the width passed to New.
func NewWorkQueue ¶
NewWorkQueue creates a WorkQueue that allows at most width jobs to run simultaneously.