Documentation
¶
Overview ¶
Package pqueue implements a priority queue.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AcquireMulti ¶
func AcquireMulti[T any](ctx context.Context, e T, qList ...*Queue[T]) (context.Context, func(), error)
AcquireMulti is used to simultaneously lock multiple queues without the risk of deadlock. The returned context needs to be used on calls to [Acquire] or [TryAcquire] which will immediately succeed since the resource is already acquired. Attempting to acquire other resources with [Acquire], [TryAcquire], or AcquireMulti using the returned context and will fail for being outside of the transaction. The returned function must be called to release the resources. The returned function is not thread safe, ensure no other simultaneous calls to [Acquire] or [TryAcquire] using the returned context have finished before it is called.
Types ¶
type Opts ¶
type Opts[T any] struct { Max int // maximum concurrent entries, defaults to 1. Next func(queued, active []*T) int // function to lookup index of next queued entry to release, defaults to oldest entry. }
Opts is used to configure a new priority queue.
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
func (*Queue[T]) Acquire ¶
Acquire adds a new entry to the queue and returns once it is ready. The returned function must be called when the queued job completes to release the next entry. If there is any error, the returned function will be nil.
func (*Queue[T]) TryAcquire ¶
TryAcquire attempts to add an entry on to the list of active entries. If the returned function is nil, the queue was not available. If the returned function is not nil, it must be called when the job is complete to release the next entry.