feat: add virtual machine scan command (#2910)

Co-authored-by: knqyf263 <knqyf263@gmail.com>
This commit is contained in:
Masahiro331
2022-11-27 18:45:00 +09:00
committed by GitHub
parent 531eaa8f06
commit 22d92e4ad6
56 changed files with 2436 additions and 144 deletions

View File

@@ -0,0 +1,30 @@
package semaphore
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(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)
}