|
|
@ -5,16 +5,19 @@ import (
|
|
|
|
"github.com/tal-tech/go-zero/core/rescue"
|
|
|
|
"github.com/tal-tech/go-zero/core/rescue"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// A TaskRunner is used to control the concurrency of goroutines.
|
|
|
|
type TaskRunner struct {
|
|
|
|
type TaskRunner struct {
|
|
|
|
limitChan chan lang.PlaceholderType
|
|
|
|
limitChan chan lang.PlaceholderType
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NewTaskRunner returns a TaskRunner.
|
|
|
|
func NewTaskRunner(concurrency int) *TaskRunner {
|
|
|
|
func NewTaskRunner(concurrency int) *TaskRunner {
|
|
|
|
return &TaskRunner{
|
|
|
|
return &TaskRunner{
|
|
|
|
limitChan: make(chan lang.PlaceholderType, concurrency),
|
|
|
|
limitChan: make(chan lang.PlaceholderType, concurrency),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Schedule schedules a task to run under concurrency control.
|
|
|
|
func (rp *TaskRunner) Schedule(task func()) {
|
|
|
|
func (rp *TaskRunner) Schedule(task func()) {
|
|
|
|
rp.limitChan <- lang.Placeholder
|
|
|
|
rp.limitChan <- lang.Placeholder
|
|
|
|
|
|
|
|
|
|
|
|