polling

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const UpdateIntervalKey = "update_interval_ms"

Variables

View Source
var Never = time.Date(9999, 1, 1, 0, 0, 0, 0, time.UTC)

Never is a disabled periodic deadline, distinct from a zero/initial deadline

Functions

func Interval

func Interval(settings map[string]any, fallback time.Duration) time.Duration

Interval preserves a caller's existing default (including adaptive and legacy intervals) unless the binding explicitly overrides it. Invalid saved values retain that default; editors use Resolve to report errors before saving

func Next

func Next(now time.Time, interval time.Duration) time.Time

Calculate the next deadline for an enabled interval

func RetryDelay

func RetryDelay(interval time.Duration, failures int, jitter float64) time.Duration

Calculate bounded retry backoff with jitter

Types

type PollState

type PollState struct {
	Next       time.Time
	Failures   int
	LastValue  any
	Stale      bool
	ObservedAt time.Time
	Available  bool
}

PollState stores a resource's last good sample independently of its subscribers

func (*PollState) Complete

func (p *PollState) Complete(value any, failed bool, now time.Time, interval time.Duration, jitter float64, retryAt time.Time)

Store a polling outcome and compute its next attempt

type RefreshPolicy

type RefreshPolicy struct {
	DefaultMS int64 `json:"default_ms"`
	MinimumMS int64 `json:"minimum_ms"`
	MaximumMS int64 `json:"maximum_ms"`
}

RefreshPolicy describes periodic reads only, never command execution

func (RefreshPolicy) Resolve

func (p RefreshPolicy) Resolve(settings map[string]any) (time.Duration, error)

Resolve a refresh interval from validated settings

type Resources

type Resources struct {
	States map[string]PollState
	// contains filtered or unexported fields
}

func NewResources

func NewResources() *Resources

Create the shared polling-resource registry

func (*Resources) Begin

func (r *Resources) Begin(key string) (uint64, error)

Start a resource poll with a new generation

func (*Resources) Complete

func (r *Resources) Complete(key string, generation uint64, value any, failed bool, now time.Time, jitter float64, retryAt time.Time) bool

Accept a current poll result and ignore obsolete generations

func (*Resources) CompleteInvalidated added in v0.1.1

func (r *Resources) CompleteInvalidated(key string, generation uint64, now time.Time, jitter float64, retryAt time.Time) bool

CompleteInvalidated accepts a current denied poll and clears every subscribed view of its previously authorized value while preserving retry scheduling.

func (*Resources) Deadline

func (r *Resources) Deadline(key string) time.Time

Deadline includes a service cooldown even after an explicit invalidation

func (*Resources) Due

func (r *Resources) Due(now time.Time) []string

List resources whose next polls are due

func (*Resources) Snapshot

func (r *Resources) Snapshot(context string) (PollState, bool)

Read the shared poll state watched by a binding

func (*Resources) Unwatch

func (r *Resources) Unwatch(context string)

Remove a binding watcher and release unused resources

func (*Resources) Watch

func (r *Resources) Watch(context, key string, interval time.Duration) error

Attach a binding watcher to a shared resource

Jump to

Keyboard shortcuts

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