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 ¶
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.