Help us shape the future of Go! Take the 2026 Go Developer Survey

refresh

package
v0.15.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package refresh models the cadence of a periodic poll: the current interval, pause and resume, and additive backoff when the server reports a rate limit. It computes durations only — it owns no timer and starts no goroutine — so the caller decides when to sleep or reschedule.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ticker

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

Ticker tracks a poll interval that can be paused and stretched under rate limiting. It holds a base interval (the steady-state cadence) and a current interval that backoff inflates and Resume restores. A Ticker carries no synchronization and is not safe for concurrent use.

func NewTicker

func NewTicker(seconds int) *Ticker

NewTicker returns a Ticker whose base and current interval are seconds. A non-positive seconds falls back to 30s, so a misconfigured cadence never becomes a busy loop.

func (*Ticker) BackoffRateLimit

func (t *Ticker) BackoffRateLimit(retryAfter time.Duration)

BackoffRateLimit lengthens the interval by retryAfter after a rate-limit response, so polling eases off rather than hammering a throttled server. A non-positive retryAfter doubles the current interval as a fallback. Backoff accumulates until Resume resets it.

func (*Ticker) Interval

func (t *Ticker) Interval() time.Duration

Interval returns the current poll interval, including any accumulated rate-limit backoff.

func (*Ticker) Pause

func (t *Ticker) Pause()

Pause marks the ticker paused. It does not change the interval; callers check Paused before acting on a tick.

func (*Ticker) Paused

func (t *Ticker) Paused() bool

Paused reports whether the ticker is paused.

func (*Ticker) Resume

func (t *Ticker) Resume()

Resume clears the paused flag and resets the interval to the base cadence, discarding any backoff accumulated while rate-limited.

Jump to

Keyboard shortcuts

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