MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / NewWithArgs

Function NewWithArgs

internal/goman/lib.go:49–78  ·  view source on GitHub ↗

NewWithArgs 创建带有参数的goroutine

(f func(args ...interface{}), args ...interface{})

Source from the content-addressed store, hash-verified

47
48// NewWithArgs 创建带有参数的goroutine
49func 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
81func List() []*Instance {

Callers 1

TestNewWithArgsFunction · 0.92

Calls 2

LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestNewWithArgsFunction · 0.74