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 ¶
- func Counting(ctx context.Context, inFlight *InFlight) context.Context
- func Detached(ctx context.Context) (context.Context, context.CancelFunc)
- func Outlasting0(outlive Outliving, name string, write func(context.Context) error) func(context.Context) error
- func Outlasting1[A any](outlive Outliving, name string, write func(context.Context, A) error) func(context.Context, A) error
- func Outlasting2[A, B any](outlive Outliving, name string, write func(context.Context, A, B) error) func(context.Context, A, B) error
- 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
- func OutlastingAnswer0[R any](outlive Outliving, name string, write func(context.Context) (R, error)) func(context.Context) (R, error)
- func OutlastingAnswer1[A, R any](outlive Outliving, name string, write func(context.Context, A) (R, error)) func(context.Context, A) (R, error)
- 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)
- func OutlastingAnswer3[A, B, C, R any](outlive Outliving, name string, ...) func(context.Context, A, B, C) (R, error)
- func OutlastingRun0(outlive Outliving, name string, run func(context.Context) (proc.Output, error)) func(context.Context) (proc.Output, error)
- func OutlastingRun1[A any](outlive Outliving, name string, ...) func(context.Context, A) (proc.Output, error)
- func Unending(ctx context.Context, _ string) (context.Context, context.CancelFunc)
- func Until(ctx, end context.Context) (context.Context, context.CancelFunc)
- func Within(ctx, end context.Context) context.Context
- type InFlight
- type Outliving
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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.
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 ¶
CountedIn is the InFlight ctx carries, or, where it carries none, one that nothing waits on.
func NewInFlight ¶
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 ¶
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 ¶
Names are the work in flight now, each piece by its name, in the order it began.
type Outliving ¶ added in v0.12.0
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
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
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.