Skip to content

Instantly share code, notes, and snippets.

@codemodify
Last active July 5, 2020 01:31
Show Gist options
  • Save codemodify/edaac2fa8723edbe5ee253d0c26950ad to your computer and use it in GitHub Desktop.
Save codemodify/edaac2fa8723edbe5ee253d0c26950ad to your computer and use it in GitHub Desktop.
go-crashproof.go
package main
import (
crashproof "github.com/codemodify/systemkit-crashproof"
)
func main() {
// 1. Catch crashes
crashproof.ConcurrentCodeCrashCatcher = reportCrash
crashproof.RunAppAndCatchCrashes(func() {
// 2. write your concurrent app
...
crashproof.Go(func(){
crashproof.Go(func(){
crashproof.Go(func(){
crashproof.Go(func(){
panic("OOPS")
})
})
})
})
...
})
}
func reportCrash(err interface{}, packageName string, callStack []crashproof.StackFrame) {
fmt.Fprintf(os.Stderr, "\n\nCRASH: %v\n\npackage %s\n\nstack: %v\n\n", err, packageName, callStack)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment