Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Forever ¶
Run executes the given function in a resilient and continuous manner until the provided context is canceled. It ensures that the function, identified by the 'name' parameter for logging purposes, is executed repeatedly. In case of a panic within the function, Run recovers from the panic, logs the error, and retries the function execution. This mechanism allows for uninterrupted operation of critical functions that must run continuously in the background.
Parameters:
- ctx: A context.Context used to control the cancellation of the function execution. When this context is canceled, the function execution stops gracefully.
- name: A string that identifies the function being executed. This name is used in logging for easier identification of log entries related to this function execution.
- f: The RunFunc to be executed. This function should contain the core logic that needs to run resiliently.
Usage: Pass a context to control when the function should stop, a descriptive name for logging, and the function itself. The function will run continuously, handling any panics, until the context is canceled.
Types ¶
type RunFunc ¶
RunFunc defines the type for functions that will be executed in a resilient manner. These functions are expected to perform their tasks continuously until the provided context is canceled. Any panics that occur within a RunFunc are recovered, and the function is retried, ensuring uninterrupted execution.
type SignalHandler ¶
SignalHandler defines the handler function type for signals.
type SignalNotifier ¶
type SignalNotifier struct {
// contains filtered or unexported fields
}
SignalNotifier configures listening for system signals.
func NewNotifier ¶
func NewNotifier(handler SignalHandler, signals ...os.Signal) *SignalNotifier
Notifier creates a new instance of SignalNotifier. It allows customizing the signals to listen for and defines an optional handler.
func (*SignalNotifier) Listen ¶
func (sn *SignalNotifier) Listen(ctx context.Context)
Listen starts listening for the configured signals. It stops when the context is canceled.
func (*SignalNotifier) ShutdownChan ¶
func (sn *SignalNotifier) ShutdownChan() <-chan struct{}
ShutdownChan returns the channel that will be closed when it's time to shut down.