github.com/lingyao2333/mo-zero@v1.4.1/core/syncx/barrier.go (about)

     1  package syncx
     2  
     3  import "sync"
     4  
     5  // A Barrier is used to facility the barrier on a resource.
     6  type Barrier struct {
     7  	lock sync.Mutex
     8  }
     9  
    10  // Guard guards the given fn on the resource.
    11  func (b *Barrier) Guard(fn func()) {
    12  	Guard(&b.lock, fn)
    13  }
    14  
    15  // Guard guards the given fn with lock.
    16  func Guard(lock sync.Locker, fn func()) {
    17  	lock.Lock()
    18  	defer lock.Unlock()
    19  	fn()
    20  }