Documentation ¶
Overview ¶
Package fatal provides a way to handle fatal errors.
- It gives the main goroutine an opportunity to cleanly shut down in case of a fatal error.
- If main goroutine is non-responsive it terminates the process.
- To improve debugging, after the first fatal error the other goroutines are given a grace period so that we have more logs to investigate.
Also implemented is a clean shutdown option, for non-error events that trigger clean application shutdown (e.g., a signal received from the user).
The main program should call fatal.Init() when it's starting.
Any library producing fatal errors should call fatal.Check() when it starts.
Index ¶
Constants ¶
const ( // FatalDelayInterval is the interval between when a package signals that a // fatal event has occurred, and when drainers of the fatal channel are // informed. This allows for collecting more informative logs before // tearing the application down. FatalDelayInterval = time.Second // FatalGraceInterval is the time in which the main goroutine should shut // the application down. FatalGraceInterval = 5 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func Check ¶
func Check()
Check checks whether the package was initialized. This MUST be called when a library producing fatal errors starts is initialized.
func FatalChan ¶
func FatalChan() <-chan struct{}
FatalChan returns a read-only channel that is closed when a fatal condition has occurred.
func Init ¶
func Init()
Init Initializes the package. This MUST be called in the main coroutine when it starts.
func Shutdown ¶
Shutdown closes the shutdown channel, thus informing channel drainers (usually the main goroutine) that the application should be cleanly shut down. If the application does not shut down in the specified duration, it is forcefully torn down.
Shutdown blocks forever.
func ShutdownChan ¶
func ShutdownChan() <-chan struct{}
ShutdownChan returns a read-only channel that is closed when the application should be cleanly shut down.
Types ¶
This section is empty.