utils

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

package utils provides a minimal-overhead, coalescing ticker.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FmtMem

func FmtMem(bytes int64) string

func NewTicker

func NewTicker(ctx context.Context, interval time.Duration) <-chan struct{}

NewTicker returns a channel that emits ticks starting immediately and then roughly every `interval` thereafter.

Design goals:

  • Single goroutine, single time.Timer (no busy waits, no extra deps).
  • Coalescing semantics: if the consumer is slow, ticks do NOT accumulate. The channel is buffered with size 1; sending is non-blocking.
  • Monotonic scheduling: next tick time is advanced by fixed `interval` from the *ideal* schedule (next += interval), preserving cadence and avoiding bursts if we ever fall behind.
  • Cancellation via ctx.Done().
  • If interval <= 0, falls back to 1s.

First tick is sent immediately (best for “kick off then repeat” workflows).

Types

This section is empty.

Jump to

Keyboard shortcuts

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