WithReadOnlyLock executes the provided function after placing a read lock on `path`. The lock is released once the function has been run, regardless of outcome.
(path string, function func() error)
| 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. |
| 116 | func WithReadOnlyLock(path string, function func() error) (err error) { |
| 117 | file, err := ReadOnlyLock(path) |
| 118 | if err != nil { |
| 119 | return err |
| 120 | } |
| 121 | |
| 122 | defer func() { |
| 123 | err = errors.Join(Unlock(file), err) |
| 124 | }() |
| 125 | |
| 126 | return function() |
| 127 | } |
searching dependent graphs…