feat(flag): replace '--slow' with '--parallel' (#5572)

Signed-off-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
Teppei Fukuda
2023-11-15 15:41:13 +09:00
committed by GitHub
parent 5372067611
commit ac0e327492
31 changed files with 115 additions and 141 deletions

View File

@@ -4,27 +4,9 @@ import "golang.org/x/sync/semaphore"
const defaultSize = 5
type options struct {
size int64
}
type option func(*options)
func WithDefault(n int64) option {
return func(opts *options) {
opts.size = defaultSize
func New(parallel int) *semaphore.Weighted {
if parallel == 0 {
parallel = defaultSize
}
}
func New(slow bool, opts ...option) *semaphore.Weighted {
o := &options{size: defaultSize}
for _, opt := range opts {
opt(o)
}
if slow {
// Process in series
return semaphore.NewWeighted(1)
}
// Process in parallel
return semaphore.NewWeighted(o.size)
return semaphore.NewWeighted(int64(parallel))
}