Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPanicRecovered is returned via done channel if a panic arises within the goroutine. ErrPanicRecovered = &goroutineError{msg: "panic recovered"} // ErrRecoverFunctionPanicked is returned via done channel if a panic arises within the // goroutine and also within the recover function. ErrRecoverFunctionPanicked = &goroutineError{msg: "recover function panicked"} )
Functions ¶
func Go ¶
func Go(f func()) <-chan error
Go runs a function f in a separate goroutine, which does handle the recovering from panic within that goroutine. Starting a new goroutine without taking care of recovering from a possible panic in that goroutine itself could crash the whole application. Functions with more than one input param must be wrapped within a func(){} like in the example below. Instead of running:
go func(s string) {
panic(s)
}("Hello World")
simply call:
Go(func() {
func(s string) {
panic(s)
}("Hello World")
})
func Goroutine ¶
func Goroutine(f func()) *goroutine
Goroutine creates a new panic safe goroutine, with the defaultRecoverFunc as recover function.
func SetDefaultRecoverFunc ¶
func SetDefaultRecoverFunc(recF RecoverFunc)
SetDefaultRecoverFunc can be used to override the defaultRecoverFunc which is used by Go and Goroutine functions. Note: Calling panic() within the recover function recF, will cause the application to crash.
If you pass nil as a RecoverFunc, the panic will be silently recovered.
Types ¶
type RecoverFunc ¶
type RecoverFunc func(v interface{}, done chan<- error)
The RecoverFunc type defines the signature of a recover function within a goroutine.
func GetDefaultRecoverFunc ¶
func GetDefaultRecoverFunc() RecoverFunc
GetDefaultRecoverFunc returns the current default recover function for goroutines used by the Go and Goroutine functions.