Documentation ¶
Index ¶
- func Crash(v interface{})
- func FxOnDone(doneChan <-chan struct{}, onDone func(context.Context), lifecycle fx.Lifecycle)
- func Go(f func())
- func RegisterPanicHandler(ph PanicHandler)
- func RegisterPanicHandlers(in PanicHandlerRegistryIn)
- type Callstack
- type CancellableWaitGroup
- type Entry
- type Function
- type Location
- type PanicHandler
- type PanicHandlerOut
- type PanicHandlerRegistry
- type PanicHandlerRegistryIn
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Crash ¶
func Crash(v interface{})
Crash calls registry's internal Crash function to invoke registered panic handler.
func FxOnDone ¶ added in v2.17.0
FxOnDone is a helper that wraps NewCancellableWaitGroup + GoOnDone in an fx lifecycle. It registers a callback to be called when the given channel is closed.
The callback will be called only within period between Start and Stop (if channel is closed before Start, callback will be delayed to until Start).
func Go ¶
func Go(f func())
Go calls registry's internal Go function to start f on a new go routine.
func RegisterPanicHandler ¶
func RegisterPanicHandler(ph PanicHandler)
RegisterPanicHandler calls global registry's internal register panic handler function to panic handler registry.
func RegisterPanicHandlers ¶
func RegisterPanicHandlers(in PanicHandlerRegistryIn)
RegisterPanicHandlers register panic handlers to panic handler registry.
Types ¶
type Callstack ¶
type Callstack []uintptr
Callstack is a full stacktrace.
func (Callstack) GetEntries ¶
GetEntries returns stacktrace of Callstack in map[string]interface{} format.
type CancellableWaitGroup ¶ added in v2.17.0
type CancellableWaitGroup struct {
// contains filtered or unexported fields
}
CancellableWaitGroup combines a WaitGroup with a cancellable context.
The zero value of CancellableWaitGroup is not usable.
func NewCancellableWaitGroup ¶ added in v2.17.0
func NewCancellableWaitGroup() *CancellableWaitGroup
NewCancellableWaitGroup creates a new CancellableWaitGroup.
func (*CancellableWaitGroup) CancelAndWait ¶ added in v2.17.0
func (cwg *CancellableWaitGroup) CancelAndWait()
CancelAndWait cancels all the running goroutines and waits for them to finish.
func (*CancellableWaitGroup) Ctx ¶ added in v2.17.0
func (cwg *CancellableWaitGroup) Ctx() context.Context
Ctx returns the context that will be canceled on Cancel.
func (*CancellableWaitGroup) Go ¶ added in v2.17.0
func (cwg *CancellableWaitGroup) Go(f func(context.Context))
Go spawns a new goroutine in the WaitGroup using panichandler.Go.
func (*CancellableWaitGroup) GoOnDone ¶ added in v2.17.0
func (cwg *CancellableWaitGroup) GoOnDone(doneChan <-chan struct{}, onDone func(context.Context))
GoOnDone registers a callback to be called when the given channel is closed. Waiting can be canceled using CancelAndWait.
type Entry ¶
type Entry struct { // Location holds the physical location for this entry. Location Location // Location holds the logical location for this entry. Function Function // PC is the program counter for this entry. PC uintptr }
Entry holds the human understandable form of a StackTrace entry.
type Function ¶
type Function struct { // Package is the go package the stack entry is from. Package string // Name is the function name the stack entry is from. Name string }
Function holds the logical location of a stack entry.
type Location ¶
type Location struct { // Directory is the directory the source file is from. Directory string // File is the filename of the source file. File string // Line is the line index in the file. Line int }
Location holds the physical location of a stack entry.
type PanicHandler ¶
type PanicHandler func(interface{}, Callstack)
PanicHandler is a panic handling function that is called when a panic occurs with full stacktrace.
type PanicHandlerOut ¶
type PanicHandlerOut struct { fx.Out PanicHandler PanicHandler `group:"panic-handlers"` }
PanicHandlerOut enables registering panic handlers via Fx.
type PanicHandlerRegistry ¶
type PanicHandlerRegistry struct { Handlers []PanicHandler // contains filtered or unexported fields }
PanicHandlerRegistry defines a list of panic handlers.
func (*PanicHandlerRegistry) Crash ¶
func (r *PanicHandlerRegistry) Crash(v interface{})
Crash invokes each of the registered panic handler and then rethrows panic - shutting down the app.
func (*PanicHandlerRegistry) Go ¶
func (r *PanicHandlerRegistry) Go(f func())
Go calls f on a new go-routine, reporting panics to the registered handlers.
func (*PanicHandlerRegistry) RegisterPanicHandler ¶
func (r *PanicHandlerRegistry) RegisterPanicHandler(ph PanicHandler)
RegisterPanicHandler appends panic handler to list of global registry's panic handler.
type PanicHandlerRegistryIn ¶
type PanicHandlerRegistryIn struct { fx.In Handlers []PanicHandler `group:"panic-handlers"` }
PanicHandlerRegistryIn holds parameters, list of panic handlers, for RegisterPanicHandlers.
type WaitGroup ¶ added in v2.17.0
type WaitGroup struct {
// contains filtered or unexported fields
}
WaitGroup allows spawning and waiting for goroutines.
(This is similar to https://pkg.go.dev/github.com/sourcegraph/conc#WaitGroup, but using the panichandler.Go to spawn goroutines).
The zero value of WaitGroup is usable, just like sync.WaitGroup.