Permalink
Browse files

Implement interval($seconds), as per S29:265

  • Loading branch information...
1 parent 6baad97 commit 3952e96965432b46beed3ca119a4937bd2b67a0d @lizmat lizmat committed Jun 28, 2013
Showing with 21 additions and 0 deletions.
  1. +21 −0 src/core/control.pm
View
@@ -220,6 +220,27 @@ sub sleep($seconds = $Inf) { # fractional seconds also allowed
return time - $time1;
}
+my %interval_wakeup; # needs to be hidden from GLOBAL:: somehow
+sub interval($seconds ) { # fractional seconds also allowed
+
+ my $time = now.Num;
+ my $wakeup := %interval_wakeup{"thread_id"} //= $time; # XXX thread ID
+
+ # already past our morning call
+ if $time >= $wakeup {
+ $wakeup += $seconds;
+ 0;
+ }
+
+ # still time to sleep
+ else {
+ my $slept = $wakeup - $time;
+ nqp::sleep($slept);
+ $wakeup += $seconds;
+ $slept;
+ }
+}
+
sub QX($cmd) {
my Mu $pio := nqp::open(nqp::unbox_s($cmd), 'rp');
fail "Unable to execute '$cmd'" unless $pio;

0 comments on commit 3952e96

Please sign in to comment.