syncutil

package
v1.3.13 Latest Latest
Warning

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

Go to latest
Published: May 12, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WaitDone added in v1.3.13

func WaitDone(fn func(done func()))

Types

type SyncedQ

type SyncedQ struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewSyncedQ

func NewSyncedQ() *SyncedQ

func (*SyncedQ) PeekFront

func (sq *SyncedQ) PeekFront() (any, bool)

func (*SyncedQ) PopFront

func (sq *SyncedQ) PopFront() any

Waits until a value is available

func (*SyncedQ) PushBack

func (sq *SyncedQ) PushBack(v any)

type ThrottledTrigger added in v1.3.13

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

ThrottledTrigger calls a function after a period of inactivity (idle), or unconditionally once the max duration is reached — whichever comes first. Typical use: coalescing rapid updates (e.g. terminal redraws) into a single call, avoiding intermediate frames.

func NewThrottledTrigger added in v1.3.13

func NewThrottledTrigger(fn func(), idle, max time.Duration) *ThrottledTrigger

NewThrottledTrigger creates a ThrottledTrigger that calls fn when triggered. idle: how long to wait after the last Trigger() call before firing.

Each new Trigger() resets this window. Use a small value (e.g. 2ms)
to coalesce bursts of updates into a single paint.

max: the maximum time to wait before firing, even if Trigger() keeps

being called continuously. Prevents starvation during sustained
output (e.g. cat largefile). Use ~16ms for ~60fps.

func (*ThrottledTrigger) Trigger added in v1.3.13

func (t *ThrottledTrigger) Trigger()

Trigger marca como dirty e arma os timers.

type Throttler added in v1.3.13

type Throttler struct {
	sync.Mutex

	Interval time.Duration
	Fn       func(done func())
	// contains filtered or unexported fields
}

runs fn only one at a time without overlaps, and always runs one last time.

func NewThrottler added in v1.3.13

func NewThrottler() *Throttler

func (*Throttler) Call added in v1.3.13

func (thr *Throttler) Call()

ensure scheduled

type WaitForSet

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

Continously usable, instantiated once for many wait()/set() calls. Fails if wait() is not ready when set() is called. Usage:

w:=NewWaitForSet()
w.Start(5*time.Second)
...
// sync/async call to w.Set()
...
v,err := w.WaitForSet()
if err!=nil {
}

func NewWaitForSet

func NewWaitForSet() *WaitForSet

func (*WaitForSet) Cancel

func (w *WaitForSet) Cancel()

In case waitforset() is not going to be called.

func (*WaitForSet) Set

func (w *WaitForSet) Set(v any) error

Fails if not able to set while get() is ready.

func (*WaitForSet) Start

func (w *WaitForSet) Start(timeout time.Duration)

func (*WaitForSet) WaitForSet

func (w *WaitForSet) WaitForSet() (any, error)

Jump to

Keyboard shortcuts

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