lifecycle

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package lifecycle provides a concurrency-safe close guard that tracks whether a resource has been closed and signals waiters via a channel.

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyClosed = errors.New("lifecycle: already closed")

ErrAlreadyClosed is returned by Guard.Close when the guard is already closed.

Functions

This section is empty.

Types

type Guard

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

Guard is a concurrency-safe close guard. It tracks whether Close has been called and provides a Done channel for goroutines to wait on.

func New

func New() *Guard

New creates a new open Guard.

func (*Guard) Close

func (g *Guard) Close() error

Close marks the guard as closed and closes the Done channel. Returns ErrAlreadyClosed if called more than once.

func (*Guard) Done

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

Done returns a channel that is closed when Guard.Close is called. Callers can use this with select to detect shutdown.

func (*Guard) IsClosed

func (g *Guard) IsClosed() bool

IsClosed reports whether the guard has been closed.

Jump to

Keyboard shortcuts

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