Skip to content

Commit 627b8e5

Browse files
committed
refactor: SafeGoCommonFunc
1 parent 62f0847 commit 627b8e5

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func RuneReverse(s string) string
182182
func RuneSubString(s string, length int, suffix string) string
183183
func S2B(s string) []byte
184184
func SafeGo(fn func(), cb ...RecoveryCallback)
185-
func SafeGoCommonFunc(ctx context.Context, args interface{}, ...)
185+
func SafeGoCommonFunc(args interface{}, fn func(args interface{}), cb ...RecoveryCallback)
186186
func SafeGoWithContext(ctx context.Context, fn func(ctx context.Context), cb ...RecoveryCallback)
187187
func SearchInt(slice []int, n int) int
188188
func SearchString(ss []string, s string) int

runtime.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,9 @@ func SafeGoWithContext(ctx context.Context, fn func(ctx context.Context), cb ...
9696
}
9797

9898
// SafeGoCommonFunc 带 Recover 的 goroutine 运行
99-
func SafeGoCommonFunc(
100-
ctx context.Context,
101-
args interface{},
102-
fn func(ctx context.Context, args interface{}),
103-
cb ...RecoveryCallback,
104-
) {
99+
func SafeGoCommonFunc(args interface{}, fn func(args interface{}), cb ...RecoveryCallback) {
105100
defer Recover(cb...)
106-
fn(ctx, args)
101+
fn(args)
107102
}
108103

109104
// WaitSignal 等待系统信号

runtime_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func TestSafeGo(t *testing.T) {
2727
time.Sleep(5 * time.Millisecond)
2828
assert.Equal(t, "fn1", err)
2929
assert.Equal(t, true, bytes.Contains(trace, []byte("panic")))
30-
SafeGoCommonFunc(ctx, nil, testFn4, rcb)
30+
SafeGoCommonFunc(ctx, testFn4, rcb)
3131
time.Sleep(5 * time.Millisecond)
3232
assert.Equal(t, "fn1", err)
3333
assert.Equal(t, true, bytes.Contains(trace, []byte("panic")))
@@ -43,7 +43,7 @@ var (
4343
testFn3 = func(ctx context.Context) {
4444
testFn1()
4545
}
46-
testFn4 = func(ctx context.Context, args interface{}) {
46+
testFn4 = func(args interface{}) {
4747
testFn1()
4848
}
4949
)

0 commit comments

Comments
 (0)