【发布时间】:2021-07-15 07:41:04
【问题描述】:
我删除了以下类型
type TestFn func(id int, ctx context.Context) error
var Func1 = TestFn(func(id int, ctx context.Context) error {
// do some work -- the execution block is concurrent safe
}
var Func2 = TestFn(func(id int, ctx context.Context) error {
// do some work
}
var Func3 = TestFn(func(id int, ctx context.Context) error {
// do some work
}
func Execute()
for i := 0; i < 5; i++ {
go Func1(i, ctx)
go Func2(i, ctx)
go Func3(i, ctx)
}
}
由于 Func1、Func2、Func3 是全局变量并分配给函数,我可以在具有不同参数的多个 go 例程中运行相同的函数吗?
【问题讨论】:
标签: function go concurrency goroutine