MCPcopy Create free account
hub / github.com/devld/go-drive / NewVMPool

Function NewVMPool

script/pool.go:37–57  ·  view source on GitHub ↗
(baseVM *VM, config *VMPoolConfig)

Source from the content-addressed store, hash-verified

35}
36
37func NewVMPool(baseVM *VM, config *VMPoolConfig) *VMPool {
38 validateVMPoolConfig(config)
39 p := &VMPool{
40 base: baseVM,
41 config: *config,
42 idle: make([]idleVM, 0, config.MaxIdle),
43 changed: make(chan struct{}),
44 stop: make(chan struct{}),
45 }
46
47 now := time.Now()
48 for range config.MinIdle {
49 p.idle = append(p.idle, idleVM{vm: baseVM.Fork(), returnedAt: now})
50 p.total++
51 }
52 if config.IdleTime > 0 {
53 p.cleaner.Add(1)
54 go p.runCleaner(cleanPeriod(config.IdleTime))
55 }
56 return p
57}
58
59func validateVMPoolConfig(config *VMPoolConfig) {
60 if config == nil {

Calls 5

runCleanerMethod · 0.95
validateVMPoolConfigFunction · 0.85
cleanPeriodFunction · 0.85
ForkMethod · 0.80
AddMethod · 0.45