WithLock runs fn while holding the lock for path. The lock is always released, even if fn panics.
(path string, fn func() error)
| 50 | // WithLock runs fn while holding the lock for path. |
| 51 | // The lock is always released, even if fn panics. |
| 52 | func (m *FileLockManager) WithLock(path string, fn func() error) error { |
| 53 | lock := m.getLock(path) |
| 54 | lock.Lock() |
| 55 | defer lock.Unlock() |
| 56 | return fn() |
| 57 | } |