Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Return Cancellation for time-based scheduled work.
  • Loading branch information
jnthn committed Apr 21, 2014
1 parent b4fcf26 commit 77d8bbd
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/core/ThreadPoolScheduler.pm
Expand Up @@ -74,26 +74,29 @@ my class ThreadPoolScheduler does Scheduler {

# need repeating
if $every {
nqp::timer($!queue,
my $handle := nqp::timer($!queue,
&catch
?? -> { code(); CATCH { default { catch($_) } } }
!! &code,
($delay * 1000).Int, ($every * 1000).Int,
TimerCancellation);
self!maybe_new_thread() if !$!started_any
self!maybe_new_thread() if !$!started_any;
return Cancellation.new(async_handles => [$handle]);
}

# only after waiting a bit or more than once
elsif $delay or $times > 1 {
my $todo := &catch
?? -> { code(); CATCH { default { catch($_) } } }
!! &code;
my @async_handles;
for 1 .. $times {
nqp::timer($!queue, $todo, ($delay * 1000).Int, 0,
TimerCancellation);
@async_handles.push(nqp::timer($!queue, $todo,
($delay * 1000).Int, 0, TimerCancellation));
$delay = 0;
}
self!maybe_new_thread() if !$!started_any
self!maybe_new_thread() if !$!started_any;
return Cancellation.new(:@async_handles);
}

# just cue the code
Expand All @@ -105,6 +108,7 @@ my class ThreadPoolScheduler does Scheduler {
self!maybe_new_thread()
if !$!started_any || $loads > 1;
nqp::push($!queue, &run);
return Nil;
}
}

Expand Down

0 comments on commit 77d8bbd

Please sign in to comment.