lifetime

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lifetime tracks in-flight operations on an owned native handle.

Acquire and Release delimit an operation that borrows the native handle. Close marks the handle closed, waits for every acquired operation to release it, and then runs the close function exactly once. Concurrent callers of Close wait for the same release to finish.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Resource

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

Resource owns one native handle and its in-flight operation count.

func New

func New(closeFn func()) *Resource

New returns a resource that calls closeFn after the last operation releases and Close has been requested. closeFn is called exactly once.

func (*Resource) Acquire

func (r *Resource) Acquire() bool

Acquire registers one in-flight operation. It reports false when the resource is already closed or closing.

func (*Resource) Close

func (r *Resource) Close()

Close marks the resource closed and waits for in-flight operations before calling the close function. It is idempotent; concurrent callers wait for the first caller to finish.

func (*Resource) Cond

func (r *Resource) Cond() *sync.Cond

Cond returns the condition variable used to wait for in-flight operations. It exists so package-level tests can observe the transition into Wait without timing assumptions. Callers must not signal or broadcast it.

func (*Resource) Release

func (r *Resource) Release()

Release ends one operation registered by Acquire.

Jump to

Keyboard shortcuts

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