github.com/cilium/cilium@v1.16.2/pkg/cleanup/cleanup.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package cleanup
     5  
     6  import (
     7  	"sync"
     8  )
     9  
    10  // DeferTerminationCleanupFunction will execute the given function `f` when the
    11  // channel `ch` is closed.
    12  // The given waitGroup will be added with a delta +1 and once the function
    13  // `f` returns from its execution that same waitGroup will signalize function
    14  // `f` is completed.
    15  func DeferTerminationCleanupFunction(wg *sync.WaitGroup, ch <-chan struct{}, f func()) {
    16  	wg.Add(1)
    17  	go func() {
    18  		defer wg.Done()
    19  		<-ch
    20  		f()
    21  	}()
    22  }