]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/DS.pm
AddTimer: avoid clock_gettime for the '0' case
[public-inbox.git] / lib / PublicInbox / DS.pm
index e7db2034c868a78a64bbaf18d3f23e25a9f0040b..ed04feb5c9e0d699feb0a4b05252aa29b8faa1aa 100644 (file)
@@ -113,8 +113,13 @@ Returns a timer object which you can call C<< $timer->cancel >> on if you need t
 
 =cut
 sub AddTimer {
-    my $class = shift;
-    my ($secs, $coderef) = @_;
+    my ($class, $secs, $coderef) = @_;
+
+    if (!$secs) {
+        my $timer = bless([0, $coderef], 'PublicInbox::DS::Timer');
+        unshift(@Timers, $timer);
+        return $timer;
+    }
 
     my $fire_time = now() + $secs;