Skip to content

Commit

Permalink
Implement interval($seconds), as per S29:265
Browse files Browse the repository at this point in the history
  • Loading branch information
lizmat committed Jun 28, 2013
1 parent 6baad97 commit 3952e96
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/core/control.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3952e96

Please sign in to comment.