Timer(3pm)
π Coro::Timer β bestie edition π
okay so this is Coro::Timer, a User Contributed Perl Documentation page, and it's all about timers and timeouts, independent of any event loop. no event loop required, she's self-sufficient, she's iconic. π§β¨
πΈ NAME πΈ
Coro::Timer β timers and timeouts, independent of any event loop. periodt. π
β¨ SYNOPSIS β¨
okay so first things first, bestie, read the comment, it's important:
# This package is mostly obsoleted by Coro::AnyEvent.
use Coro::Timer qw(timeout);
# nothing exported by default
so you can pull in timeout with qw(timeout), but heads up: nothing is exported by default. she gives you nothing for free, you have to ask. π
π¦ DESCRIPTION π¦
so the tea is: this package has been mostly obsoleted by Coro::AnyEvent. like, not me delivering the news, it's literally in the docs. π
but the one really useful function that's still left in here is timeout. she survived the purge, she's the main character. π
β $flag = timeout $seconds
this function will wake up the current coroutine after $seconds seconds, and it sets $flag to true. ($flag is false initially, okay, don't come for me.)
and here's the cute part: if $flag goes out of scope earlier, then nothing happens. no wake-up, no drama, she just quietly stops existing. π
this is used by Coro itself to implement the "timed_down", "timed_wait" etc. primitives. and it gets used like this, fr fr:
sub timed_wait {
my $timeout = Coro::Timer::timeout 60;
while (condition false) {
Coro::schedule; # wait until woken up or timeout
return 0 if $timeout; # timed out
}
return 1; # condition satisfied
}
see how $timeout gets checked with return 0 if $timeout;? that's the timeout flag going true and the loop bailing. and if the condition gets satisfied first, return 1; and everybody's happy. π«Ά
ngl this whole pattern is giving "small function, huge responsibility" and I'm obsessed. π
π 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. this was Timer(3pm) from the User Contributed Perl Documentation, and the footer vibes were perl v5.40.1, dated 2025-03-21. πβ¨ππ¦πΈπ π«Άπβπ
π¦ 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