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 mix send and broadcast calls on the same Coro::Signal without 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 either send or broadcast). 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 to wait, it will not wait, but immediately return. The callback will be called under the same conditions as wait without 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