perf

package
v0.1.0-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

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

type InMemoryCoalescer[T any, S Sender[T]] struct {
	// contains filtered or unexported fields
}

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 WithContext(ctx context.Context) Option

func WithGlobalLimiter

func WithGlobalLimiter(l *rate.Limiter) Option

func WithIdleTTL

func WithIdleTTL(d time.Duration) Option

func WithInterval

func WithInterval(d time.Duration) Option

func WithLifecycle

func WithLifecycle(lc fx.Lifecycle) Option

If provided, registers Fx OnStop to call Shutdown(ctx, shutdownMode).

func WithMinGapAfterSend

func WithMinGapAfterSend(d time.Duration) Option

func WithMode

func WithMode(m CoalescerMode) Option

func WithShutdownMode

func WithShutdownMode(m ShutdownMode) Option

type Sender

type Sender[T any] interface {
	Send(ctx context.Context, key string, payload T) error
}

Sender is your overridable hook (outer struct implements this).

type ShutdownMode

type ShutdownMode int
const (
	ShutdownNoop ShutdownMode = iota
	ShutdownSendLatest
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL