background

package
v0.4.8 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package background provides sdk-internal lifecycle primitives for long-lived background work.

The package intentionally knows nothing about history, knowledge, recall, or telemetry backends. It only fixes the cross-cutting concurrency contract: owners create a cancellable context, start goroutines with Add-before-go ordering, debounce work through owner-loop signals, and classify work item outcomes consistently.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Debouncer

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

Debouncer emits one signal after a quiet period.

Reset arms or re-arms the timer. The timer callback only attempts to send on C; long-running work should happen in the owner loop that receives the signal. C has capacity 1, so signals coalesce when the owner is busy.

func NewDebouncer

func NewDebouncer(delay time.Duration) *Debouncer

NewDebouncer creates a Debouncer. Non-positive delays are normalized to 1ns so Reset still schedules work asynchronously through the timer path.

func (*Debouncer) C

func (d *Debouncer) C() <-chan struct{}

C returns the signal channel consumed by the owner loop.

func (*Debouncer) Reset

func (d *Debouncer) Reset() bool

Reset schedules a signal after the quiet period. It returns false after Stop.

func (*Debouncer) Stop

func (d *Debouncer) Stop()

Stop cancels future signals and drains any pending signal.

type Group

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

Group owns a lifecycle-bound context and a set of goroutines derived from it.

Close is idempotent. It cancels the group context, waits for every accepted goroutine to return, and then closes Done. Start synchronizes wg.Add before launching the goroutine, so callers cannot race Close's Wait with a late Add.

func NewGroup

func NewGroup(parent context.Context) *Group

NewGroup returns a fresh lifecycle group. A nil parent is treated as context.Background().

func (*Group) Close

func (g *Group) Close()

Close cancels the group context and waits for all accepted work to drain.

func (*Group) Context

func (g *Group) Context() context.Context

Context returns the owner context shared by all accepted work.

func (*Group) Done

func (g *Group) Done() <-chan struct{}

Done is closed after Close has canceled the context and all accepted work has returned.

func (*Group) Start

func (g *Group) Start(fn func(context.Context)) bool

Start launches fn in a goroutine bound to the group context. It returns false when Close has already started or fn is nil.

type Outcome

type Outcome string

Outcome is the normalized result label for a background work item.

const (
	OutcomeSucceeded Outcome = "succeeded"
	OutcomeCanceled  Outcome = "canceled"
	OutcomeTimeout   Outcome = "timeout"
	OutcomeFailed    Outcome = "failed"
)

func Classify

func Classify(err error) Outcome

Classify returns the normalized outcome for err.

func (Outcome) String

func (o Outcome) String() string

String returns the stable telemetry label for o.

Jump to

Keyboard shortcuts

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