NewWithArgs 创建带有参数的goroutine
(f func(args ...interface{}), args ...interface{})
| 47 | |
| 48 | // NewWithArgs 创建带有参数的goroutine |
| 49 | func NewWithArgs(f func(args ...interface{}), args ...interface{}) { |
| 50 | if !teaconst.IsMain { |
| 51 | return |
| 52 | } |
| 53 | |
| 54 | _, file, line, _ := runtime.Caller(1) |
| 55 | |
| 56 | go func() { |
| 57 | locker.Lock() |
| 58 | instanceId++ |
| 59 | |
| 60 | var instance = &Instance{ |
| 61 | Id: instanceId, |
| 62 | CreatedTime: time.Now(), |
| 63 | } |
| 64 | |
| 65 | instance.File = file |
| 66 | instance.Line = line |
| 67 | |
| 68 | instanceMap[instanceId] = instance |
| 69 | locker.Unlock() |
| 70 | |
| 71 | // run function |
| 72 | f(args...) |
| 73 | |
| 74 | locker.Lock() |
| 75 | delete(instanceMap, instanceId) |
| 76 | locker.Unlock() |
| 77 | }() |
| 78 | } |
| 79 | |
| 80 | // List 列出所有正在运行goroutine |
| 81 | func List() []*Instance { |