Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Build ¶
type Build[Key comparable] struct { Key Key C context.Context Cancel context.CancelCauseFunc }
Build is passed to BuildFn for build operations.
type BuildFn ¶
type BuildFn[Key comparable, Object any] func(Build[Key]) (Object, error)
BuildFn can build a resulting done-able object or fail.
type GroupTimer ¶
type GroupTimer interface {
// Join returns true if a change was made, or false if the timer had already expired.
Join(context.Context) bool
// Done returns a channel which is closed when the the last context is done and the timer has expired.
Done() <-chan struct{}
}
func NewGroupTimer ¶
func NewGroupTimer(t time.Duration, ctx context.Context) GroupTimer
NewGroupTimer builds a timer that expires in the passed duration after the last context joined is done.
type HasShutdown ¶
type HasShutdown interface {
Shutdown()
}
Objects used within Manager can optionally implement HasShutdown. If so, Shutdown is called on normal shutdown (no-one is interested in object) before the context is cancelled. This method is not called in a failure mode (listen to the context yourself).
type HasShutdownError ¶
type HasShutdownError interface {
Shutdown() error
}
Objects used within Manager can optionally implement HasShutdownError. If so, Shutdown is called on normal shutdown (no-one is interested in object) before the context is cancelled. The returned error is used to cancel the context (nil just means cancelled normally). This method is not called in a failure mode (listen to the context yourself).
type Manager ¶
type Manager[Key comparable, Object any] interface { // Run creates/joins the lifecycle of an object with the given key. // Returns an error if it could not be created - this is "sticky" while interested. // Otherwise, returns the object and its run context (detached). Run(context.Context, Key) (Object, context.Context, error) SetTimeout(time.Duration) }
Manager is a "life-cycle manager", which allows keyed creation -> use -> shutdown.
func New ¶
func New[Key comparable, Object any]( ctx context.Context, build BuildFn[Key, Object], ) Manager[Key, Object]
New returns a new Manager that manages the lifecycle of lazily-created objects. The passed initial context should be context.Background, as it is used as the parent of all lazily-created objects.