Documentation
¶
Index ¶
- type Coalescer
- type CoalescerMode
- type InMemoryCoalescer
- type Option
- func WithContext(ctx context.Context) Option
- func WithGlobalLimiter(l *rate.Limiter) Option
- func WithIdleTTL(d time.Duration) Option
- func WithInterval(d time.Duration) Option
- func WithLifecycle(lc fx.Lifecycle) Option
- func WithMinGapAfterSend(d time.Duration) Option
- func WithMode(m CoalescerMode) Option
- func WithShutdownMode(m ShutdownMode) Option
- type Sender
- type ShutdownMode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coalescer ¶
type Coalescer[T any] interface { Update(key string, payload T) StopKey(key string) Shutdown(ctx context.Context, mode ShutdownMode) // graceful stop (optionally flush) Close() // stop background GC (no flush) }
Coalescer is the interface most callers should depend on.
type CoalescerMode ¶
type CoalescerMode int
const ( TrailingOnly CoalescerMode = iota LeadingAndTrailing LeadingOnly // immediate send, then suppress for interval; no trailing send )
type InMemoryCoalescer ¶
InMemoryCoalescer is generic over payload T and sender S. S must implement Sender[T]. Pass your outer struct as S.
func NewInMemoryCoalescer ¶
func NewInMemoryCoalescer[T any, S Sender[T]](owner S, opts ...Option) (*InMemoryCoalescer[T, S], error)
NewInMemoryCoalescer is the single constructor using functional options. If WithLifecycle is set, it registers an Fx OnStop hook that calls Shutdown(ctx, shutdownMode).
func (*InMemoryCoalescer[T, S]) Close ¶
func (c *InMemoryCoalescer[T, S]) Close()
func (*InMemoryCoalescer[T, S]) Shutdown ¶
func (c *InMemoryCoalescer[T, S]) Shutdown(ctx context.Context, mode ShutdownMode)
Shutdown gracefully stops timers & GC and (optionally) sends a final “latest” per key.
func (*InMemoryCoalescer[T, S]) StopKey ¶
func (c *InMemoryCoalescer[T, S]) StopKey(key string)
func (*InMemoryCoalescer[T, S]) Update ¶
func (c *InMemoryCoalescer[T, S]) Update(key string, payload T)
type Option ¶
type Option func(*config)
func WithContext ¶
func WithGlobalLimiter ¶
func WithIdleTTL ¶
func WithInterval ¶
func WithLifecycle ¶
If provided, registers Fx OnStop to call Shutdown(ctx, shutdownMode).
func WithMinGapAfterSend ¶
func WithMode ¶
func WithMode(m CoalescerMode) Option
func WithShutdownMode ¶
func WithShutdownMode(m ShutdownMode) Option
type ShutdownMode ¶
type ShutdownMode int
const ( ShutdownNoop ShutdownMode = iota ShutdownSendLatest )
Click to show internal directories.
Click to hide internal directories.