IO::Lambda::Flock(3)

πŸ“¦ version 1.34, in alpine 3.24

πŸ’– 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:

  • timeout or deadline β€” these two are literally synonyms, both of them declare the moment when the lambda waiting for the lock should give up. if it's undef, then the timeout never occurs. never ever. it'll wait forever and that's on you. 😭
  • shared β€” if this one's set, LOCK_SH is used. otherwise you get LOCK_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 🧚

  • Fcntl
  • IO::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