| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package util
- import (
- "sync"
- "testing"
- )
- /**
- 对于非闭包函数的支持
- */
- func TestGoWithRecover(t *testing.T) {
- wg := sync.WaitGroup{}
- x := 0
- wg.Add(1)
- GoWithRecover(func() {
- defer func() {
- wg.Done()
- }()
- t.Logf("run : %d\n", x)
- t.Log(10 / x)
- }, func(r interface{}) {
- t.Logf("find err: %s\n", r)
- })
- wg.Wait()
- }
- /**
- 不支持闭包函数循环结构
- */
- func TestGoWithRecoverBiBao(t *testing.T) {
- wg := sync.WaitGroup{}
- x := 0
- wg.Add(10)
- for n := 0; n < 10; n++ {
- GoWithRecover(func() {
- defer func() {
- wg.Done()
- }()
- t.Logf("run : %d\n", n)
- t.Log(10 / x)
- }, func(r interface{}) {
- t.Logf("find err: %s\n", r)
- })
- }
- wg.Wait()
- }
|