Signal(3pm)
π Signal(3pm) β bestie edition π
okay so this is the Signal(3pm) page from the User Contributed Perl Documentation, and we're about to make semaphores cute. it's giving "concurrency but make it a group chat." let's go π«Ά
β¨ NAME β¨
Coro::Signal β thread signals (binary semaphores)
π¦ SYNOPSIS π¦
use Coro;
my $sig = new Coro::Signal;
$sig->wait; # wait for signal
# ... some other "thread"
$sig->send;
πΈ DESCRIPTION πΈ
So this module implements signals / binary semaphores / condition variables β and honestly bestie, they're basically all the same thing wearing different outfits π . You can either wait for a signal to show up, or send it, in which case it wakes up one waiter. Or you can broadcast, which wakes up all the waiters. the way that one function has main character energy π
lowkey important: it is recommended not to mixsendandbroadcastcalls on the sameCoro::Signalwithout some deep thinking. like, while it should work as documented, it can easily confuse you:->π fr fr, do not do this casually.
And good news: you don't have to load Coro::Signal manually β it gets loaded automatically when you use Coro and call the new constructor. she just shows up β¨
$sig = new Coro::Signal;β Create a new signal. fresh signal, no cap π$sig->waitβ Wait for the signal to occur (via eithersendorbroadcast). Returns immediately if the signal has been sent before. she doesn't wait around if she doesn't have to π$sig->wait ($callback)β If you pass a callback argument towait, it will not wait, but immediately return. The callback will be called under the same conditions aswaitwithout arguments would continue the thrad. (yes, "thrad." the typo is canon, we keep it π) The callback might wake up any number of threads, but is NOT allowed to block (switch to other threads). so like, no yapping on the callback's time, bestie π$sig->sendβ Send the signal, waking up one waiting process, or remember the signal if no process is waiting. it's a little memory-keeper π$sig->broadcastβ Send the signal, waking up all waiting process. If no process is waiting the signal is lost. π gone. evaporated. she left the chat.$sig->awaitedβ Return true when the signal is being awaited by some process. vibe check: is anyone out there waiting for you? π₯Ί
π AUTHOR/SUPPORT/CONTACT π
Marc A. Lehmann <schmorp@schmorp.de>
http://software.schmorp.de/pkg/Coro.html
and that's the whole page, bestie!! this was Signal(3pm), shipped with perl v5.40.1, dated 2025-03-21. mwah, slay, go write some coroutines πβ¨ππ¦
π¦ where this page comes from
- debian trixie: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libcoro-perl 6.570-4 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms