util

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backoff

func Backoff(attempt int) time.Duration

Backoff returns exponential backoff delay for attempt number (0-based).

func ParseSSE

func ParseSSE(ctx context.Context, r io.Reader, out chan<- map[string]any, errs chan<- error)

ParseSSE reads server-sent events and emits parsed JSON data objects.

Types

type IdleReader added in v0.0.5

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

IdleReader wraps an io.Reader and enforces an idle-read timeout. The internal timer is reset on every successful (n>0) Read; if the timer expires before another read completes, onIdle is invoked and subsequent Read calls return the error supplied by onIdle's caller via the wrapper's state. The zero timeout disables the timer (behaves as a plain pass-through).

func NewIdleReader added in v0.0.5

func NewIdleReader(r io.Reader, timeout time.Duration, idleErr error, onIdle func()) *IdleReader

NewIdleReader constructs an IdleReader. onIdle is called once, asynchronously, from the timer goroutine when the idle window elapses — typically used to cancel a context so the underlying Read unblocks. idleErr is substituted for any error returned by the underlying reader after the timer has fired so callers can distinguish idle timeout from generic network/context errors.

func (*IdleReader) Read added in v0.0.5

func (ir *IdleReader) Read(p []byte) (int, error)

Read implements io.Reader.

func (*IdleReader) Stop added in v0.0.5

func (ir *IdleReader) Stop()

Stop halts the idle timer. Safe to call multiple times.

Jump to

Keyboard shortcuts

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