mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-24 01:30:25 +08:00
22 lines
337 B
Go
22 lines
337 B
Go
package threading
|
|
|
|
type WorkerGroup struct {
|
|
job func()
|
|
workers int
|
|
}
|
|
|
|
func NewWorkerGroup(job func(), workers int) WorkerGroup {
|
|
return WorkerGroup{
|
|
job: job,
|
|
workers: workers,
|
|
}
|
|
}
|
|
|
|
func (wg WorkerGroup) Start() {
|
|
group := NewRoutineGroup()
|
|
for i := 0; i < wg.workers; i++ {
|
|
group.RunSafe(wg.job)
|
|
}
|
|
group.Wait()
|
|
}
|