Last active
July 5, 2020 01:31
-
-
Save codemodify/edaac2fa8723edbe5ee253d0c26950ad to your computer and use it in GitHub Desktop.
go-crashproof.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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