Copyright | (c) 2013-2016 2018 Peter Trško |
---|---|
License | BSD3 |
Maintainer | peter.trsko@gmail.com |
Stability | experimental |
Portability | GHC specific language extensions; POSIX. |
Safe Haskell | Safe |
Language | Haskell2010 |
Low-level API for providing exclusive access to a resource using lock file.
- lock :: (MonadMask m, MonadIO m) => LockingParameters -> FilePath -> m Handle
- unlock :: (MonadMask m, MonadIO m) => FilePath -> Handle -> m ()
- data LockingParameters = LockingParameters {}
- data RetryStrategy
- = No
- | Indefinitely
- | NumberOfTimes !Word8
- data LockingException
Locking primitives
lock :: (MonadMask m, MonadIO m) => LockingParameters -> FilePath -> m Handle Source #
Open lock file write PID of a current process in to it and return its handle.
If operation doesn't succeed, then LockingException
is raised. See also
LockingParameters
and RetryStrategy
for details.
unlock :: (MonadMask m, MonadIO m) => FilePath -> Handle -> m () Source #
Close lock file handle and then delete it.
Configuration
data LockingParameters Source #
Locking algorithm parameters. When in doubt, use def
, otherwise start
with it. Example:
lockedDo :: (MonadMask
m,MonadIO
m) =>FilePath
-> m a -> m a lockedDo =withLockFile
lockParams lockFile where lockParams =def
{retryToAcquireLock
=NumberOfTimes
3 } lockFile =withLockExt
"/var/lock/my-app"
LockingParameters | |
|
Eq LockingParameters Source # | |
Data LockingParameters Source # | |
Read LockingParameters Source # | |
Show LockingParameters Source # | |
Generic LockingParameters Source # | |
Default LockingParameters Source # | Defined as:
Sleep interval is inspired by |
type Rep LockingParameters Source # | |
data RetryStrategy Source #
Defines strategy for handling situations when lock-file is already acquired.
No | Don't retry at all. |
Indefinitely | Retry indefinitely. |
NumberOfTimes !Word8 | Retry only specified number of times.
If equal to zero then it is interpreted same way as |
Eq RetryStrategy Source # | |
Data RetryStrategy Source # | |
Read RetryStrategy Source # | |
Show RetryStrategy Source # | |
Generic RetryStrategy Source # | |
Default RetryStrategy Source # | Defined as: |
type Rep RetryStrategy Source # | |
Exceptions
data LockingException Source #
UnableToAcquireLockFile FilePath | Wasn't able to aquire lock file specified as an argument. |
CaughtIOException IOException |
|