linger

package
v2.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package linger contains a utility for reporting on where lingering tasks were originally started.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckClean

func CheckClean(t TestingT, r *Recorder)

CheckClean will record a test error if there are any active tasks being tracked by the Recorder. A snapshot of the stack where the tasks were launched will be written into the test log.

Types

type Recorder

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

A Recorder can be attached to a stopper.Context to record the call stack where stopper.Context.Call or stopper.Context.Go has been called. See CheckClean for ways to use a Recorder in testing scenarios.

Example
// Construct the recorder and attach it as task middleware. The
// stack depth counts away from Context.Call() or Context.Go(). If
// the package-level Call() or Go() helpers are used, the smallest
// useful depth is 2 frames.
rec := linger.NewRecorder(2 /* stack depth */)
ctx := stopper.New(
	stopper.WithTaskOptions(
		stopper.TaskMiddleware(rec.Middleware),
	))
defer ctx.Stop()

// Start some tasks.
_ = stopper.Go(ctx, func(ctx stopper.Context) {
	<-ctx.Stopping()
})

// Sample the tasks asynchronously.
stacks := rec.Callers()
for _, stack := range stacks {
	frames := runtime.CallersFrames(stack)
	for {
		frame, more := frames.Next()
		fmt.Println(frame.Function)
		if !more {
			break
		}
	}
}
Output:
vawter.tech/stopper/v2.Go[...]
vawter.tech/stopper/v2/linger_test.ExampleRecorder

func NewRecorder

func NewRecorder(depth int) *Recorder

NewRecorder constructs a Recorder that samples the call stack at the requested depth. A depth of 1 will record the location at which stopper.Context.Call or stopper.Context.Go was executed.

func (*Recorder) Callers

func (r *Recorder) Callers() [][]uintptr

Callers returns a snapshot of the caller stacks associated with any managed tasks that are currently running.

func (*Recorder) Middleware

func (r *Recorder) Middleware(outer stopper.Context) (stopper.Context, stopper.Invoker)

Middleware is a stopper.Middleware that samples the caller to stopper.Context.Call or to stopper.Context.Go.

type TestingT

type TestingT interface {
	Errorf(string, ...any)
}

TestingT is the subset of testing.TB needed by CheckClean.

Jump to

Keyboard shortcuts

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