Skip to content

Commit

Permalink
refactor: Catch panic when firing goroutine
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed Jan 16, 2024
1 parent ec00c45 commit ed582c5
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/concurrent/concurrent.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package concurrent

import (
"fmt"
"log/slog"
"runtime/debug"
"sync"
)

Expand All @@ -18,6 +21,12 @@ func (g *Simple) Go(f func()) {
go func() {
defer g.wg.Done()

defer func() {
if r := recover(); r != nil {
slog.Error(fmt.Sprintf("panic: %s", r), "error.stack", string(debug.Stack()))
}
}()

f()
}()
}
Expand Down

0 comments on commit ed582c5

Please sign in to comment.