leak

package
v0.0.0-...-cd54735 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2024 License: MIT Imports: 6 Imported by: 4

Documentation

Overview

Package leak provides a way to track resources when race detector is enabled.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Ref

type Ref struct {
}

Ref implements a Resource tracker that is only enabled when compiling with `-race`.

func FromContext

func FromContext(parent context.Context) Ref

FromContext returns the attached root Ref.

func Root

func Root(skipCallers int) Ref

Root returns a root reference to a tracker.

func WithContext

func WithContext(parent context.Context) (Ref, context.Context)

WithContext attaches a root context that handles tracking.

func (Ref) Child

func (ref Ref) Child(name string, skipCallers int) Ref

Child returns a child ref.

func (Ref) Close

func (ref Ref) Close() error

Close closes the ref and checks whether all the children have been closed.

The caller should close the ref with Ref.Close.

func (Ref) StartStack

func (ref Ref) StartStack() string

StartStack returns formatted stack where the resource was created.

type Resource

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

Resource implements tracking a nested resources.

Any child resource must be closed before the parent, otherwise closing the parent returns an error.

Note, in most cases using Ref is preferred as it won't affect performance for production builds.

func RootResource

func RootResource(skipCallers int) *Resource

RootResource returns a root resource tracker.

func (*Resource) Child

func (parent *Resource) Child(name string, skipCallers int) *Resource

Child returns a child resource.

func (*Resource) Close

func (parent *Resource) Close() error

Close closes the resource and checks whether all the children have been closed.

func (*Resource) StartStack

func (parent *Resource) StartStack() string

StartStack returns formatted stack where the resource was created.

Jump to

Keyboard shortcuts

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