Documentation
¶
Index ¶
- type Cache
- type Group
- type Option
- func WithGroupCache[K comparable, V any](cache Cache[K, V]) Option[*groupOptions[K, V]]
- func WithGroupContext[K comparable, V any](ctx context.Context) Option[*groupOptions[K, V]]
- func WithGroupTaskAutoCancel[K comparable, V any](enabled bool) Option[*groupOptions[K, V]]
- func WithTaskAutoCancel[T any](enabled bool) Option[*taskOptions[T]]
- func WithTaskContext[T any](ctx context.Context) Option[*taskOptions[T]]
- func WithTaskDone[T any](done func(val T, err error)) Option[*taskOptions[T]]
- type Task
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
Cache defines the minimalistic storage blueprint required by the Group component. It allows seamless, out-of-the-box integration with memory caches (e.g., LRU) or remote systems (e.g., Redis).
type Group ¶
type Group[K comparable, V any] struct { // contains filtered or unexported fields }
Group manages concurrent read/write coalescing across a keyspace. It leverages localized Task[V] generations to isolate hot-key synchronization.
type Option ¶
type Option[T any] interface { // contains filtered or unexported methods }
func WithGroupCache ¶
func WithGroupCache[K comparable, V any](cache Cache[K, V]) Option[*groupOptions[K, V]]
WithGroupCache configures the secondary persistence or eviction tier (e.g., an LRU cache).
func WithGroupContext ¶
func WithGroupContext[K comparable, V any](ctx context.Context) Option[*groupOptions[K, V]]
WithGroupContext attaches a long-lived supervisor context to the cache broker.
func WithGroupTaskAutoCancel ¶
func WithGroupTaskAutoCancel[K comparable, V any](enabled bool) Option[*groupOptions[K, V]]
WithGroupTaskAutoCancel propagates the dynamic early-cleanup flag down to every individual key's sub-task execution.
func WithTaskAutoCancel ¶
WithAutoCancel activates the dynamic reference telemetry tracker. If all calling contexts timeout or abort, the active worker routine is terminated via surgical context cancellation, instantly saving CPU/IO resources and preventing ghost tasks from draining the system.
func WithTaskContext ¶
WithContext binds a long-lived supervisor context (e.g., Application or Plugin lifecycle) to the initialization lifecycle. This ensures that even if individual ephemeral client requests timeout or abort, the background bootstrap routine can safely run to completion using this stable context boundary, preventing corrupted partial states.
func WithTaskDone ¶
WithDone registers a thread-safe, asynchronous post-initialization callback function. It is fully type-safe and ideal for exporting connection metrics, telemetries, dynamic pooling, or firing alerting pipelines upon bootstrap failures.
type Task ¶
type Task[T any] struct { // contains filtered or unexported fields }
Task guards the lazy initialization of a heavy resource (e.g., global singletons, configurations, or connection pools) with request coalescing capabilities. It solves 4 major concurrent pain points: thundering herd protection, resilient lazy-loading, instant response to caller context cancellations, and automated teardown of orphaned generations.
func NewTask ¶
NewTask creates a ready-to-use, type-safe Task instance using generic functional options.
func (*Task[T]) Get ¶
Get ensures that the initialization function f is called exactly once as long as it succeeds. It returns (value, shared, error). CRITICAL SEMANTIC: shared is false ONLY when the specific caller won the race and successfully completed the initialization. For all concurrent waiters, aborted requests, or failed generations, shared returns true to strongly protect upper cache layers (e.g., Redis/LRU) from duplicate/bad writes.