Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype DbLocked = DbLocked FilePath
- withLockDB ∷ MountPoint → IO a → IO a
- dbLockFsPath ∷ FsPath
- dbLockTimeout ∷ DiffTime
- withLockDB_ ∷ ∀ m a. (IOLike m, MonadTimer m) ⇒ FileLock m → MountPoint → FsPath → DiffTime → m a → m a
Documentation
withLockDB ∷ MountPoint → IO a → IO a Source #
We use an empty file (dbLockFsPath
) as a lock of the database so that
the database cannot be opened by more than one process. We wait up to
dbLockTimeout
to take the lock, before timing out and throwing a
DbLocked
exception.
Defaults
dbLockFsPath ∷ FsPath Source #
The default lock file
dbLockTimeout ∷ DiffTime Source #
Default time to wait on the lock
For testing purposes
∷ ∀ m a. (IOLike m, MonadTimer m) | |
⇒ FileLock m | |
→ MountPoint | Root of the path |
→ FsPath | File to lock |
→ DiffTime | Timeout |
→ m a | |
→ m a |
We use the given FsPath
in the MountPoint
as a lock of the database
so that the database cannot be opened by more than one process. We wait the
given DiffTime
on the thread taking the lock. In case of a timeout, we
throw a DbLocked
exception.
Some systems may delete the empty file when all its handles are closed. This is not an issue, since the file is created if it doesn't exist.