Skip to content

Commit

Permalink
fix: SafeGo runs in goroutine
Browse files Browse the repository at this point in the history
  • Loading branch information
fufuok committed Jan 19, 2024
1 parent e041f2a commit 85716b0
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,26 @@ func Recover(cb ...RecoveryCallback) {

// SafeGo 带 Recover 的 goroutine 运行
func SafeGo(fn func(), cb ...RecoveryCallback) {
defer Recover(cb...)
fn()
go func() {
defer Recover(cb...)
fn()
}()
}

// SafeGoWithContext 带 Recover 的 goroutine 运行
func SafeGoWithContext(ctx context.Context, fn func(ctx context.Context), cb ...RecoveryCallback) {
defer Recover(cb...)
fn(ctx)
go func() {
defer Recover(cb...)
fn(ctx)
}()
}

// SafeGoCommonFunc 带 Recover 的 goroutine 运行
func SafeGoCommonFunc(args interface{}, fn func(args interface{}), cb ...RecoveryCallback) {
defer Recover(cb...)
fn(args)
go func() {
defer Recover(cb...)
fn(args)
}()
}

// WaitSignal 等待系统信号
Expand Down

0 comments on commit 85716b0

Please sign in to comment.