From 2b7c5848fef857e9987bda6d9416289ca98f4807 Mon Sep 17 00:00:00 2001 From: kzkzzzz Date: Sat, 1 Jun 2024 18:47:42 +0800 Subject: [PATCH] update --- common.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 common.go diff --git a/common.go b/common.go new file mode 100644 index 0000000..2bc572a --- /dev/null +++ b/common.go @@ -0,0 +1,22 @@ +package mycommon + +import ( + "git.makemake.in/kzkzzzz/mycommon/mylog" + "runtime/debug" +) + +func SafeFn(fn func()) { + defer func() { + if err := recover(); err != nil { + mylog.Errorf("panic: %s\n%s", err, string(debug.Stack())) + } + }() + + fn() +} + +func SafeGo(fn func()) { + go func() { + SafeFn(fn) + }() +}