github.com/MetalBlockchain/metalgo@v1.11.9/x/merkledb/wait_group.go (about) 1 // Copyright (C) 2019-2024, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package merkledb 5 6 import "sync" 7 8 // waitGroup is a small wrapper of a sync.WaitGroup that avoids performing a 9 // memory allocation when Add is never called. 10 type waitGroup struct { 11 wg *sync.WaitGroup 12 } 13 14 func (wg *waitGroup) Add(delta int) { 15 if wg.wg == nil { 16 wg.wg = new(sync.WaitGroup) 17 } 18 wg.wg.Add(delta) 19 } 20 21 func (wg *waitGroup) Wait() { 22 if wg.wg != nil { 23 wg.wg.Wait() 24 } 25 }