WithLock executes a function while holding an exclusive lock.
(ctx context.Context, fn func() error)
| 123 | |
| 124 | // WithLock executes a function while holding an exclusive lock. |
| 125 | func (rl *RepositoryLock) WithLock(ctx context.Context, fn func() error) error { |
| 126 | if err := rl.Lock(ctx); err != nil { |
| 127 | return err |
| 128 | } |
| 129 | defer rl.Unlock() |
| 130 | |
| 131 | return fn() |
| 132 | } |
| 133 | |
| 134 | // WithRLock executes a function while holding a shared lock. |
| 135 | func (rl *RepositoryLock) WithRLock(ctx context.Context, fn func() error) error { |
no test coverage detected