Help us shape the future of Go! Take the 2026 Go Developer Survey

lifetime

package
v0.13.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package lifetime carries, in a context, the end of what a piece of work is done for: the web server serving it, or the command running it. Work that goes on when its asker leaves (a read others share, a refresh that must not stop halfway) detaches from the asker through Detached, and still ends with that lifetime, so a server that stops, or a command a signal ends, is never held open by it. A context can carry an InFlight too, the work begun under it that has not yet ended, which a process waits for before it exits. A write that must outlast its asker, as the terminal's writes outlast a quit, is wrapped by Outlasting0 and its kin to run under the context an Outliving makes for it: Unending, EndingWith or UncountedEndingWith.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Counting

func Counting(ctx context.Context, inFlight *InFlight) context.Context

Counting is ctx carrying inFlight, which work begun under it is counted in.

func Detached

Detached is Until(ctx, the lifetime ctx carries), or, where it carries none, a context with ctx's values that never ends but on release.

func Outlasting0 added in v0.12.0

func Outlasting0(outlive Outliving, name string, write func(context.Context) error) func(context.Context) error

Outlasting0 is write, named name, asked under the context outlive makes from its caller's and released once write returns. A nil write stays nil.

func Outlasting1 added in v0.12.0

func Outlasting1[A any](
	outlive Outliving, name string, write func(context.Context, A) error,
) func(context.Context, A) error

Outlasting1 is Outlasting0 for a write taking one argument after its context.

func Outlasting2 added in v0.12.0

func Outlasting2[A, B any](
	outlive Outliving, name string, write func(context.Context, A, B) error,
) func(context.Context, A, B) error

Outlasting2 is Outlasting0 for a write taking two arguments after its context.

func Outlasting3 added in v0.12.0

func Outlasting3[A, B, C any](
	outlive Outliving, name string, write func(context.Context, A, B, C) error,
) func(context.Context, A, B, C) error

Outlasting3 is Outlasting0 for a write taking three arguments after its context.

func OutlastingAnswer0 added in v0.12.0

func OutlastingAnswer0[R any](
	outlive Outliving, name string, write func(context.Context) (R, error),
) func(context.Context) (R, error)

OutlastingAnswer0 is Outlasting0 for a write that answers a value beside its error.

func OutlastingAnswer1 added in v0.12.0

func OutlastingAnswer1[A, R any](
	outlive Outliving, name string, write func(context.Context, A) (R, error),
) func(context.Context, A) (R, error)

OutlastingAnswer1 is Outlasting1 for a write that answers a value beside its error.

func OutlastingAnswer2 added in v0.12.0

func OutlastingAnswer2[A, B, R any](
	outlive Outliving, name string, write func(context.Context, A, B) (R, error),
) func(context.Context, A, B) (R, error)

OutlastingAnswer2 is Outlasting2 for a write that answers a value beside its error.

func OutlastingAnswer3 added in v0.12.0

func OutlastingAnswer3[A, B, C, R any](
	outlive Outliving, name string, write func(context.Context, A, B, C) (R, error),
) func(context.Context, A, B, C) (R, error)

OutlastingAnswer3 is Outlasting3 for a write that answers a value beside its error.

func OutlastingRun0 added in v0.12.0

func OutlastingRun0(
	outlive Outliving, name string, run func(context.Context) (proc.Output, error),
) func(context.Context) (proc.Output, error)

OutlastingRun0 is run, a program whose output streams on after run returns, named name and asked under the context outlive makes from its caller's, which is released, and stops counting in flight, once Wait has said how the program exited. Once its caller's context ends first, the rest of the output is read and dropped, so the program never blocks on a full pipe. A nil run stays nil.

func OutlastingRun1 added in v0.12.0

func OutlastingRun1[A any](
	outlive Outliving, name string, run func(context.Context, A) (proc.Output, error),
) func(context.Context, A) (proc.Output, error)

OutlastingRun1 is OutlastingRun0 for a run taking one argument after its context.

func Unending added in v0.12.0

Unending is a write's context never ending, with nothing to release: for writes nothing has yet given an end.

func Until

func Until(ctx, end context.Context) (context.Context, context.CancelFunc)

Until is a context with ctx's values that goes on when ctx ends and ends when end does, with end's cause, and the function that releases it once the work it was made for is done.

func Within

func Within(ctx, end context.Context) context.Context

Within is ctx carrying end as the lifetime work detached under it ends with, in place of any it carried before.

Types

type InFlight

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

InFlight is the work begun under one lifetime that has not yet ended, each piece named for what it does: what a process waits for before it exits, so it does not cut that work off.

func CountedIn

func CountedIn(ctx context.Context) *InFlight

CountedIn is the InFlight ctx carries, or, where it carries none, one that nothing waits on.

func NewInFlight

func NewInFlight(settle time.Duration) *InFlight

NewInFlight is work in flight, none yet, that Settled takes to have settled once nothing has been in flight for settle: a piece that follows another in one step begins just as the first ends, and is waited for too.

func (*InFlight) Begin

func (f *InFlight) Begin(name string) func()

Begin counts a piece of work named name in flight until the function it returns is called; calling that again does nothing.

func (*InFlight) Names

func (f *InFlight) Names() []string

Names are the work in flight now, each piece by its name, in the order it began.

func (*InFlight) Settled

func (f *InFlight) Settled(ctx context.Context) ([]string, error)

Settled returns once nothing has been in flight for the settle NewInFlight was given. When ctx ends first, it answers the names of the work still in flight then, with ctx's cause, or nothing at all when none is.

type Outliving added in v0.12.0

type Outliving func(ctx context.Context, name string) (context.Context, context.CancelFunc)

Outliving is how a write's context outlives its caller's: the context to write under, with ctx's values and not its end, for the write name says, and the function that releases it once the write is done.

func EndingWith added in v0.12.0

func EndingWith(program context.Context) Outliving

EndingWith is a write's context ending when program does, the write counted in flight, by its name, in the InFlight program carries (CountedIn) until it is released, so the process can wait for it before it exits.

func UncountedEndingWith added in v0.12.0

func UncountedEndingWith(program context.Context) Outliving

UncountedEndingWith is a context ending when program does, for work counted nowhere, which the process does not wait for before it exits: an opener may run the browser in the foreground until the browser closes.

Jump to

Keyboard shortcuts

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