opio

package
v0.0.0-...-011bec4 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultInterruptSignals = []os.Signal{
	os.Interrupt,
	os.Kill,
	syscall.SIGTERM,
	syscall.SIGQUIT,
}

DefaultInterruptSignals is a set of default interrupt signals.

Functions

func BlockOnInterrupts

func BlockOnInterrupts(signals ...os.Signal)

BlockOnInterrupts blocks until a SIGTERM is received. Passing in signals will override the default signals.

func BlockOnInterruptsContext

func BlockOnInterruptsContext(ctx context.Context, signals ...os.Signal)

BlockOnInterruptsContext blocks until a SIGTERM is received. Passing in signals will override the default signals. The function will stop blocking if the context is closed.

func CancelOnInterrupt

func CancelOnInterrupt(ctx context.Context) context.Context

CancelOnInterrupt cancels the given context on interrupt. If a BlockFn is attached to the context, this is used as interrupt-blocking. If not, then the context blocks on a manually handled interrupt signal.

func WithBlocker

func WithBlocker(ctx context.Context, fn BlockFn) context.Context

WithBlocker overrides the interrupt blocker value, e.g. to insert a block-function for testing CLI shutdown without actual process signals.

func WithInterruptBlocker

func WithInterruptBlocker(ctx context.Context) context.Context

WithInterruptBlocker attaches an interrupt handler to the context, which continues to receive signals after every block. This helps functions block on individual consecutive interrupts.

Types

type BlockFn

type BlockFn func(ctx context.Context)

BlockFn simply blocks until the implementation of the blocker interrupts it, or till the given context is cancelled.

func BlockerFromContext

func BlockerFromContext(ctx context.Context) BlockFn

BlockerFromContext returns a BlockFn that blocks on interrupts when called.

Jump to

Keyboard shortcuts

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