WithLock executes the provided function after placing a write lock on `path`. The lock is released once the function has been run, regardless of outcome.
(path string, function func() error)
| 99 | // WithLock executes the provided function after placing a write lock on `path`. |
| 100 | // The lock is released once the function has been run, regardless of outcome. |
| 101 | func WithLock(path string, function func() error) (err error) { |
| 102 | file, err := Lock(path) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | defer func() { |
| 108 | err = errors.Join(Unlock(file), err) |
| 109 | }() |
| 110 | |
| 111 | return function() |
| 112 | } |
| 113 | |
| 114 | // WithReadOnlyLock executes the provided function after placing a read lock on `path`. |
| 115 | // The lock is released once the function has been run, regardless of outcome. |
searching dependent graphs…