fixed unhandled panic and wrapped all internal goroutines

This commit is contained in:
Gani Georgiev
2026-07-15 12:03:07 +03:00
parent 09044ef7a3
commit f1618ee59b
13 changed files with 85 additions and 37 deletions
+15
View File
@@ -1,6 +1,7 @@
package routine
import (
"fmt"
"log"
"runtime"
"sync"
@@ -33,3 +34,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()
}
}