notifier

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package notifier shares one Postgres LISTEN connection between subscribers and reconnects when it drops.

Index

Constants

View Source
const (
	DefaultMinBackoff  = 100 * time.Millisecond
	DefaultMaxBackoff  = 5 * time.Second
	DefaultIdleTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Listener    job.Listener
	Clock       clock.Clock
	Logger      *slog.Logger
	MinBackoff  time.Duration
	MaxBackoff  time.Duration
	IdleTimeout time.Duration
	OnConnect   func()
	Rand        func() float64
}

type Notifier

type Notifier struct {
	// contains filtered or unexported fields
}

Notifier delivers notifications from one LISTEN connection to its subscribers.

func New

func New(cfg Config) (*Notifier, error)

New validates cfg and applies defaults.

func (*Notifier) Connected

func (n *Notifier) Connected() bool

func (*Notifier) Run

func (n *Notifier) Run(ctx context.Context) error

Run listens and reconnects until ctx is cancelled.

func (*Notifier) Subscribe

func (n *Notifier) Subscribe(channel string, fn func(payload string))

Subscribe registers fn to run for notifications on channel.

Jump to

Keyboard shortcuts

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