github.com/ava-labs/avalanchego@v1.11.11/vms/rpcchainvm/runtime/subprocess/stopper.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package subprocess 5 6 import ( 7 "context" 8 "os/exec" 9 "sync" 10 11 "github.com/ava-labs/avalanchego/utils/logging" 12 "github.com/ava-labs/avalanchego/vms/rpcchainvm/runtime" 13 ) 14 15 func NewStopper(logger logging.Logger, cmd *exec.Cmd) runtime.Stopper { 16 return &stopper{ 17 cmd: cmd, 18 logger: logger, 19 } 20 } 21 22 type stopper struct { 23 once sync.Once 24 cmd *exec.Cmd 25 logger logging.Logger 26 } 27 28 func (s *stopper) Stop(ctx context.Context) { 29 s.once.Do(func() { 30 stop(ctx, s.logger, s.cmd) 31 }) 32 }