add syncx.Guard func (#620)
This commit is contained in:
@@ -9,7 +9,12 @@ type Barrier struct {
|
||||
|
||||
// Guard guards the given fn on the resource.
|
||||
func (b *Barrier) Guard(fn func()) {
|
||||
b.lock.Lock()
|
||||
defer b.lock.Unlock()
|
||||
Guard(&b.lock, fn)
|
||||
}
|
||||
|
||||
// Guard guards the given fn with lock.
|
||||
func Guard(lock sync.Locker, fn func()) {
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
fn()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user