Created
November 6, 2021 08:37
-
-
Save TBXark/74065c92455b94e1fa2df4637eaffe6c to your computer and use it in GitHub Desktop.
Safe goroutine
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
func Go(f func()) { | |
go func() { | |
defer func() { | |
if err := recover(); err != nil { | |
fmt.Println("Recover:", err) | |
} | |
}() | |
f() | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment