IO::Lambda::Flock(3)
π IO::Lambda::Flock(3) β the group chat version π
okay so real talk, bestie: this is a page from the User Contributed Perl Documentation section, and it's all about IO::Lambda::Flock. sit down, grab a strawberry π, we're doing file locking the cute way.
β¨ NAME β¨
IO::Lambda::Flock β file locking, but lambda-style. that's it, that's the name. iconic. π
πΈ DESCRIPTION πΈ
so this module gives you a file locking interface for the lambda style, and how does it pull that off? by using non-blocking, periodic polling of flock(2). that's the whole vibe β no blocking, just vibing and checking again later. ngl it's kind of a whole personality. π¦
π SYNOPSIS π
here's the serve, look at this:
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 }
};
see how it flows? lock, read, print a little dot to show status. main character energy fr fr. β¨
π API π
flock($filehandle, %options) -> ($lock_obtained = 1 | $timeout = 0)
this is the one, bestie. it waits until the file lock is obtained or the timeout is expired β whichever comes first, no cap. when it's successful, the (shared or exclusive) lock on $filehandle gets acquired by the flock($filehandle, LOCK_NB) call. and it hands you back either 1 for "yay, locked" or 0 for "timeout, we gave up". π«Ά
and here are the options, one by one, because we don't skip:
timeoutordeadlineβ these two are literally synonyms, both of them declare the moment when the lambda waiting for the lock should give up. if it'sundef, then the timeout never occurs. never ever. it'll wait forever and that's on you. πsharedβ if this one's set,LOCK_SHis used. otherwise you getLOCK_EX. simple as that.frequencyβ defines how often the polling for the lock should occur. if you leave it undefined, polling occurs during idle time, when other events are dispatched. iykyk π
π§ SEE ALSO π§
FcntlIO::Lambda::Poll
go read those too, they're part of the lore. π
π AUTHOR π
Dmitry Karasik, <dmitry@karasik.eu.org>. thank you king π
okay so that's the whole page! and for the cute sign-off: this little beauty is perl v5.42.2, dated 2026-02-15, filed under IO::Lambda::Flock(3) π like, that's the whole footer, we just made it fashion. bye bestie, go lock some files ππ₯
π¦ where this page comes from
- alpine 3.24: perl-io-lambda-doc 1.34-r1 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms