Documentation
¶
Overview ¶
Package simultaneous exists to place a limit on simultaneous actions that need a limit.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrTimeout errors.String = "could not get permission to run before timeout"
Functions ¶
This section is empty.
Types ¶
type Enforced ¶
type Enforced[T any] interface { // contains filtered or unexported methods }
Enforced is a type that exists just to signal that a simultaneous limit is being enforced. When passing a Limited as a argument, have the receiver take an Enforced instead.
type Limit ¶
type Limit[T any] struct { // contains filtered or unexported fields }
Limit implements Enforced so it can be used to fulfill the Enforced contract.
func New ¶
New takes both a type and a count. The type is so that if the limit is passed around it can be done so with type safety so that a limit of one kind of thing cannot be used as limit of another kind of thing. If you're not passing the resulting limit around, then the type argument can be anything. Like "string".
func (*Limit[T]) Forever ¶
Forever waits until there is space in the Limit for another simultaneous runner. It will wait forever. The Done() method must be called to release the space.
defer limit.Forever().Done()
func (Limit[T]) SetForeverMessaging ¶
func (l Limit[T]) SetForeverMessaging(stuckTimeout time.Duration, stuckCallback func(), unstuckCallback func()) *Limit[T]
SetForeverMessaging returns a modified Limit that changes the behavior of Forever() so that it will call stuckCallback() (if set) after waiting for stuckTimeout duration. If past that duration, and it will call unstuckCallback() (if set) when it finally gets a limit.