Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LockGroup ¶
type LockGroup struct {
// contains filtered or unexported fields
}
LockGroup is a map of mutex that locks entries with different id separately. It's used levitate lock contentions of using a global lock.
func NewLockGroup ¶
func NewLockGroup(options ...LockGroupOption) *LockGroup
NewLockGroup create and return an empty lockGroup.
type LockGroupOption ¶
type LockGroupOption func(lg *LockGroup)
LockGroupOption configures the lock group.
func WithHash ¶
func WithHash(hashFn func(id uint32) uint32) LockGroupOption
WithHash sets the lockGroup's hash function to provided hashFn.
func WithRemoveEntryOnUnlock ¶
func WithRemoveEntryOnUnlock(removeEntryOnUnlock bool) LockGroupOption
WithRemoveEntryOnUnlock sets the lockGroup's removeEntryOnUnlock to provided value.
type Mutex ¶
Mutex is a mutual exclusion lock. The zero value for a Mutex is an unlocked mutex.
Mutex must not be copied after first use.
type OrderedSingleFlight ¶
type OrderedSingleFlight[TResult any] struct { // contains filtered or unexported fields }
OrderedSingleFlight is a utility to make concurrent calls to a function internally only one execution, and shares the execution result to the outer callers. This is similar to the normal singleflight.Group from golang.org/x/sync/singleflight package, but with the following differences:
- Key is not supported. An OrderedSingleFlight instance runs only one function.
- The invocation and inner execution is *strongly ordered*, which means, a call to Do gets the result of an execution that is guaranteed to started after the beginning of the invocation, and an earlier execution that started before the current invocation to Do won't be reused for this call. If there's already an execution running in progress and a call to Do happens, it enters the next batch instead of sharing the result of the already-started execution.
- The return type is generic, instead of interface{}.
func NewOrderedSingleFlight ¶
func NewOrderedSingleFlight[TResult any]() *OrderedSingleFlight[TResult]
NewOrderedSingleFlight creates an instance of OrderedSingleFlight.
func (*OrderedSingleFlight[TResult]) Do ¶
func (s *OrderedSingleFlight[TResult]) Do(ctx context.Context, f func(context.Context) (TResult, error)) (TResult, error)
Do tries to execute the function `f`, or if possible, wait and reuse the result of an execution triggered by another goroutine. See comments of OrderedSingleFlight for details.
func (*OrderedSingleFlight[TResult]) ExecCount ¶
func (s *OrderedSingleFlight[TResult]) ExecCount() int64
ExecCount returns the accumulated number of executions of the inner function.