Documentation
¶
Overview ¶
Package lockset contains a utility type that orders access to multiple resources.
Index ¶
- func Wait(ctx context.Context, outcomes []Outcome) error
- type Callback
- type Outcome
- type Queue
- func (q *Queue[K, V]) Dequeue(val V) ([]V, bool)
- func (q *Queue[K, V]) Enqueue(keys []K, val V) (atHead bool, err error)
- func (q *Queue[K, V]) IsEmpty() bool
- func (q *Queue[K, V]) IsHead(val V) bool
- func (q *Queue[K, V]) IsQueuedKey(key K) bool
- func (q *Queue[K, V]) IsQueuedValue(val V) bool
- func (q *Queue[K, V]) IsTail(val V) bool
- func (q *Queue[K, V]) PeekHead() (V, bool)
- func (q *Queue[K, V]) PeekTail() (V, bool)
- type RetryAtHeadErr
- type Runner
- type Set
- type Status
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Outcome ¶
Outcome is a convenience type alias.
func NewOutcome ¶
func NewOutcome() Outcome
NewOutcome is a convenience method to allocate an Outcome.
type Queue ¶
type Queue[K comparable, V comparable] struct { // contains filtered or unexported fields }
A Queue implements an in-order admission queue for arbitrary values associated with a set of potentially-overlapping keys.
A Queue is internally synchronized and is safe for concurrent use. A Queue should not be copied after it has been created.
func NewQueue ¶
func NewQueue[K comparable, V comparable]() *Queue[K, V]
NewQueue constructs a Queue.
func (*Queue[K, V]) Dequeue ¶
Dequeue removes the value from the queue and returns any newly-unblocked values. The bool return value indicates whether the value was in the queue.
func (*Queue[K, V]) Enqueue ¶
Enqueue returns true if the value is at the head of its key queues. It is an error to enqueue a value if it is already enqueued.
func (*Queue[K, V]) IsQueuedKey ¶
IsQueuedKey returns true if the key is present in the queue.
func (*Queue[K, V]) IsQueuedValue ¶
IsQueuedValue returns true if the value is present in the queue.
type RetryAtHeadErr ¶
type RetryAtHeadErr struct {
// contains filtered or unexported fields
}
RetryAtHeadErr is returned by RetryAtHead.
func RetryAtHead ¶
func RetryAtHead(cause error) *RetryAtHeadErr
RetryAtHead returns an error that tasks can use to be retried later, once all preceding tasks have completed. If this error is returned when there are no preceding tasks, the causal error will be emitted from Set.Schedule.
func (*RetryAtHeadErr) Or ¶
func (e *RetryAtHeadErr) Or(fn func()) *RetryAtHeadErr
Or sets a fallback function to invoke if the task was already at the head of the global queue. This is used if a cleanup task must be run if the task is not going to be retried. The receiver is returned.
func (*RetryAtHeadErr) Unwrap ¶
func (e *RetryAtHeadErr) Unwrap() error
Unwrap returns the causal error passed to RetryAtHead.
type Runner ¶
type Runner interface { // Go should execute the function in a non-blocking fashion. Go(func(context.Context)) error }
A Runner is passed to New to begin the execution of tasks.
type Set ¶
type Set[K comparable] struct { // contains filtered or unexported fields }
Set implements an in-order admission queue for actors requiring exclusive access to a set of keys.
A Set is internally synchronized and is safe for concurrent use. A Set should not be copied after it has been created.
func New ¶
func New[K comparable](runner Runner, metricsLabel string) (*Set[K], error)
New construct a Set that executes tasks using the given runner.
See GoRunner
func (*Set[K]) Schedule ¶
Schedule executes the Callback once all keys have been locked. The result from the callback is available through the returned variable.
Callbacks that need to be retried may return RetryAtHead. This will execute the callback again when all other callbacks scheduled before it have been completed. A retrying callback will continue to hold its key locks until the retry has taken place.
It is valid to call this method with an empty key slice. The callback will simply be executed in a separate goroutine.
The provided key slice will be deduplicated to avoid a callback from deadlocking with itself.
Callbacks must not schedule new tasks and proceed to wait upon them. This will lead to deadlocks.
The cancel function may be called to asynchronously dequeue and cancel the callback. If the callback has already started executing, the cancel callback will have no effect.
type Status ¶
type Status struct {
// contains filtered or unexported fields
}
Status is returned by Set.Schedule.
func StatusFor ¶
StatusFor constructs a successful status if err is null. Otherwise, it returns a new Status object that returns the error.
func (*Status) Completed ¶
Completed returns true if the callback has been called. See also Status.Success.
func (*Status) Retrying ¶
Retrying returns true if the callback returned RetryAtHead and it has not yet been re-attempted.