NAME
IO::Lambda::Flock - lambda-style file locking
DESCRIPTION
The module provides file locking interface for the lambda style, implemented by using non-blocking, periodic polling of flock(2).
SYNOPSIS
open LOCK, ">lock";
lambda {
# obtain the lock
context \*LOCK, timeout => 10;
flock { die "can't obtain lock" unless shift }
# while reading from handle
context $handle;
readable { ... }
# and showing status
context 0.5;
timeout { print '.'; again }
};
API
- flock($filehandle, %options) -> ($lock_obtained = 1 | $timeout = 0)
-
Waits until the file lock is obtained or the timeout is expired. When successful, the (shared or exclusive) lock on
$filehandle
is acquired byflock($filehandle, LOCK_NB)
call. Options:timeout
ordeadline
-
These two options are synonyms, both declare the moment when the lambda waiting for the lock should give up. If undef, timeout never occurs.
-
If set,
LOCK_SH
is used, otherwiseLOCK_EX
. - frequency
-
Defines how often the polling for the lock should occur. If left undefined, polling occurs during idle time, when other events are dispatched.
SEE ALSO
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.