fix golint issues in core/threading (#524)
This commit is contained in:
@@ -2,10 +2,12 @@ package threading
|
||||
|
||||
import "sync"
|
||||
|
||||
// A RoutineGroup is used to group goroutines together and all wait all goroutines to be done.
|
||||
type RoutineGroup struct {
|
||||
waitGroup sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewRoutineGroup returns a RoutineGroup.
|
||||
func NewRoutineGroup() *RoutineGroup {
|
||||
return new(RoutineGroup)
|
||||
}
|
||||
|
||||
@@ -5,16 +5,19 @@ import (
|
||||
"github.com/tal-tech/go-zero/core/rescue"
|
||||
)
|
||||
|
||||
// A TaskRunner is used to control the concurrency of goroutines.
|
||||
type TaskRunner struct {
|
||||
limitChan chan lang.PlaceholderType
|
||||
}
|
||||
|
||||
// NewTaskRunner returns a TaskRunner.
|
||||
func NewTaskRunner(concurrency int) *TaskRunner {
|
||||
return &TaskRunner{
|
||||
limitChan: make(chan lang.PlaceholderType, concurrency),
|
||||
}
|
||||
}
|
||||
|
||||
// Schedule schedules a task to run under concurrency control.
|
||||
func (rp *TaskRunner) Schedule(task func()) {
|
||||
rp.limitChan <- lang.Placeholder
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package threading
|
||||
|
||||
// A WorkerGroup is used to run given number of workers to process jobs.
|
||||
type WorkerGroup struct {
|
||||
job func()
|
||||
workers int
|
||||
}
|
||||
|
||||
// NewWorkerGroup returns a WorkerGroup with given job and workers.
|
||||
func NewWorkerGroup(job func(), workers int) WorkerGroup {
|
||||
return WorkerGroup{
|
||||
job: job,
|
||||
@@ -12,6 +14,7 @@ func NewWorkerGroup(job func(), workers int) WorkerGroup {
|
||||
}
|
||||
}
|
||||
|
||||
// Start starts a WorkerGroup.
|
||||
func (wg WorkerGroup) Start() {
|
||||
group := NewRoutineGroup()
|
||||
for i := 0; i < wg.workers; i++ {
|
||||
|
||||
Reference in New Issue
Block a user