SHARYA...:Flock(3pm)

πŸ“¦
version 0.56 Β· 2 versions
  • 0.56 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.56 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– SHARYA...:Flock β€” the manual page, but make it cute πŸ’–

okay bestie, we're in the User Contributed Perl Documentation section, and this little page lives under the name SHARYA...:Flock. yes the title is truncated, that's just how the man page header rolls, don't come for it. πŸ’…


✨ NAME ✨

SHARYANTO::File::Flock β€” yet another flock module πŸ¦‹


🌸 VERSION 🌸

version 0.56


πŸŽ€ SYNOPSIS πŸŽ€

use SHARYANTO::File::Flock;

# try to acquire exclusive lock. if fail to acquire lock within 60s, die.
my $lock = SHARYANTO::File::Flock->lock($file);

# explicitly unlock
$lock->release;

# automatically unlock if object is DESTROY-ed.
undef $lock;

like, that's the whole vibe. grab a lock, drop the lock, or just let the object go out of scope and let it handle itself. main character energy fr. πŸ‘‘


πŸ’œ DESCRIPTION πŸ’œ

This is yet another flock module. It's a more lightweight alternative to File::Flock, with some other differences too:

  • OO interface only, periodt. no sneaky procedural stuff.
  • Autoretry (by default for 60s) when trying to acquire a lock.

ngl, I prefer this approach over blocking/waiting indefinitely or just failing immediately. like, give it a minute, it's trying its best. 😭


🫢 METHODS 🫢

$lock = SHARYANTO::File::Flock->lock($path, \%opts)

Acquire an exclusive lock on $path. And listen β€” $path will be created if it doesn't already exist. ✨ If $path is already locked by another process, it will retry (by default for 60 seconds). Will die if it fails to acquire the lock. πŸ’€

It will automatically unlock if $lock goes out of scope. Upon unlock, it will remove $path if it was created and is still empty (this behavior is the same as File::Flock). cute, tidy, considerate. 🧚

Available options:

  • retries => INT (default: 60) β€” number of retries (which equals the number of seconds, since the retry happens every second).

$lock->unlock

Unlock. that's it. that's the whole thing. πŸ”“

$lock->release

Synonym for unlock(). same energy, different name. πŸ’…


πŸ™ˆ CAVEATS πŸ™ˆ

Not yet tested on Windows. Some filesystems do not support inode? πŸ‘€ (yes, with the question mark, I'm just the messenger)

lowkey important: this is untested territory on Windows, and the inode thing is genuinely an open question. don't be shocked if a filesystem gives you the side-eye.

🌈 SEE ALSO 🌈


πŸ‘‘ AUTHOR πŸ‘‘

Steven Haryanto <stevenharyanto@gmail.com>


This software is copyright (c) 2013 by Steven Haryanto.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


⭐ FUNCTIONS ⭐

None are exported by default, but they are exportable. so like, nothing shows up unless you ask for it. consent-first exports, we love to see it. 🫢


and that's a wrap bestie!! 🌸 this page was living in perl v5.34.0 and got its last lil glow-up on 2022-06-17, and the man page name is SHARYA...:Flock(3pm) in case you need to cite your sources. slay, go lock some files responsibly. πŸ’…βœ¨

πŸ“¦ where this page comes from