fixed unhandled panic and wrapped all internal goroutines

This commit is contained in:
Gani Georgiev committed 2026-07-15 13:41:10 +03:00
1 parent a6deb6ab90
commit 30b4184305
11 files changed
+76 -22

No files matched your search

+15
View File
@@ -1,6 +1,7 @@
package routine
import (
"fmt"
"log"
"runtime/debug"
"sync"
@@ -30,3 +31,17 @@ func FireAndForget(f func(), wg ...*sync.WaitGroup) {
f()
}()
}
// SafeWrap wraps the provided function with auto panic recover handling
// and returns any eventual panic as regular error.
func SafeWrap(f func() error) func() error {
return func() (err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("[SafeWrap] recovered from panic: %v", r)
}
}()
return f()
}
}