Documentation
¶
Overview ¶
Implements interrupts: events that normally signal intent to cancel a Context, but may be repeated to encourage closure of new Contexts used to clean up resources.
Index ¶
- func Wait(ctx context.Context) error
- func WithCancelOnInterrupt(ctx context.Context) context.Context
- func WithSignalWaiter(ctx context.Context) (_ context.Context, stop func())
- func WithSignalWaiterMain(ctx context.Context) context.Context
- func WithWaiterFunc(ctx context.Context, fn WaiterFunc) context.Context
- type WaiterFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wait ¶
Wait blocks until an interrupt is received, defaulting to interrupting on the default signals if no interrupt blocker is present in the Context. Returns nil if an interrupt occurs, else the Context error when it's done.
func WithCancelOnInterrupt ¶
WithCancelOnInterrupt returns a Context that is cancelled when Wait returns on the waiter in ctx. If there's no waiter, the default interrupt signals are used: In this case the signal hooking is not stopped until the original ctx is cancelled.
func WithSignalWaiter ¶
WithSignalWaiter attaches an interrupt signal handler to the context which continues to receive signals after every wait, and also prevents the interrupt signals being handled before we're ready to wait for them. This helps functions wait on individual consecutive interrupts.
func WithSignalWaiterMain ¶
WithSignalWaiterMain returns a Context with a signal interrupt blocker and leaks the destructor. Intended for use in main functions where we exit right after using the returned context anyway.
func WithWaiterFunc ¶
func WithWaiterFunc(ctx context.Context, fn WaiterFunc) context.Context
WithInterruptWaiter overrides the interrupt waiter value, e.g. to insert a function that mocks interrupt signals for testing CLI shutdown without actual process signals.
Types ¶
type WaiterFunc ¶
Waits for an interrupt or context cancellation. ctxErr should be the context.Cause of ctx when it is done. interrupt is only inspected if ctxErr is nil, and is not required to be set.