Storable(3pm)

πŸ’– Storable(3pm) β€” Coro::Storable πŸ’–

okay bestie, so this is a page from the User Contributed Perl Documentation section of the manual, and it's about Coro::Storable, which is giving "Storable but make it cooperative" energy. let's get into it 🫢


✨ NAME ✨

Coro::Storable β€” offer a more fine-grained Storable interface πŸŽ€


🌸 SYNOPSIS 🌸

use Coro::Storable;

that's literally it. one line. she's low maintenance. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this module implements a few functions from the Storable module, but in a way that cedes more often. because sometimes β€” and hear me out β€” some applications (like the Deliantra game server, for example) need to load large Storable objects without blocking the server for a long, long time. and blocking the server? not the vibe. not today. 😭

the way it does this is by using a perlio layer that feeds only small amounts of data into Storable β€” specifically 4096 bytes per call β€” and calling Coro::cede regularly. how regularly, you ask? at most 100 times per second by default, though. so like, she's polite about it. ✨

now here's the important part, and I need you to really hear me on this: Storable is not reentrant. so this module also wraps most functions of the Storable module so that only one freeze or thaw happens at any one moment. and jsyk β€” recursive invocations are not currently supported. that's a real limitation, not a cute quirk. πŸ’€


πŸ‘‘ FUNCTIONS πŸ‘‘

πŸ“ $ref = thaw $pst

retrieve an object from the given $pst, which must have been created with Coro::Storable::freeze or Storable::store_fd / Storable::store. and yeah, sorry bestie β€” Storable uses incompatible formats for disk and memory objects, so you can't just mix and match. πŸ™ˆ

this function will cede regularly. πŸ’–

πŸ“ $pst = freeze $ref

freeze the given scalar $ref into a Storable object. it uses the same format as Storable::store_fd.

this functino will cede regularly. (yes, "functino". the original really said that and honestly? iconic typo. we're keeping it. 😌)

πŸ“ $pst = nfreeze $ref

same as freeze, but it's compatible with Storable::nstore_fd β€” and note the n, bestie, the n is doing heavy lifting here. πŸ‘‘

πŸ“ $pst = blocking_freeze $ref

same as freeze, but it is guaranteed to block. and that's actually a feature, not a bug β€” it's useful e.g. in Coro::Util::fork_eval when you want to serialise a data structure for use with the thaw function for this module. ⭐

you cannot use Storable::freeze for this, because Storable uses incompatible formats for memory and file images, and this module uses file images. so like, don't. fr fr. πŸ’€

πŸ“ $pst = blocking_nfreeze $ref

same as blocking_freeze, but it uses nfreeze internally. πŸ’…

πŸ“ $guard = guard

acquire the Storable lock β€” for when you want to call Storable yourself. main character energy, going in solo. 🌈

but ngl, note that this module already wraps all Storable functions, so there is rarely any need to do this yourself. the lock is right there. she's handled. 🫢

πŸ’œ AUTHOR/SUPPORT/CONTACT πŸ’œ

Marc A. Lehmann <schmorp@schmorp.de>

http://software.schmorp.de/pkg/Coro.html


and that's the whole page, bestie!! no cap, every flag and function accounted for. this one came out of perl v5.40.1, dated 2025-03-21, under the Storable(3pm) name β€” so if you cite her, cite her right. mwah. πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from