The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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 by flock($filehandle, LOCK_NB) call. Options:

timeout or deadline

These two options are synonyms, both declare the moment when the lambda waiting for the lock should give up. If undef, timeout never occurs.

shared

If set, LOCK_SH is used, otherwise LOCK_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

Fcntl, IO::Lambda::Poll.

AUTHOR

Dmitry Karasik, <dmitry@karasik.eu.org>.