Skip to content
Permalink
Browse files

Throw X::Scheduler::CueInNaNSeconds instead of dying

  • Loading branch information...
Kaiepi committed May 6, 2019
1 parent c977d6c commit 9b46cb90d96f604ba6ac17c8cde82b44deabe1e6
Showing with 9 additions and 3 deletions.
  1. +1 −1 src/core/CurrentThreadScheduler.pm6
  2. +6 −0 src/core/Scheduler.pm6
  3. +2 −2 src/core/ThreadPoolScheduler.pm6
@@ -25,7 +25,7 @@ my class CurrentThreadScheduler does Scheduler {
($delay := 0),
nqp::if(
nqp::isnanorinf($delay),
(die "Cannot set NaN as a number of seconds")
X::Scheduler::CueInNaNSeconds.new().throw()
)
)
)
@@ -2,6 +2,12 @@
# that schedulers must do, as well as a way to factor out some common "sugar"
# and infrastructure.

my class X::Scheduler::CueInNaNSeconds is Exception {
method message(--> Str) {
'Cannot pass NaN as a number of seconds to Scheduler.cue'
}
}

my role Scheduler {
has &.uncaught_handler is rw;

@@ -842,7 +842,7 @@ my class ThreadPoolScheduler does Scheduler {
# Checks if the value given is Inf, -Inf, or NaN. If NaN, this throws.
# if Inf, this returns Nil for ThreadPoolScheduler.cue to return an empty
# Cancellation for. If -Inf, returns 0. Otherwise, returns the value.
sub validate-seconds(Numeric() $value) {
sub validate-seconds(Numeric() $value --> Seconds) {
nqp::unless(
nqp::istype($value, Num),
$value,
@@ -854,7 +854,7 @@ my class ThreadPoolScheduler does Scheduler {
0,
nqp::if(
nqp::isnanorinf($value),
die("Cannot set NaN as a number of seconds"),
X::Scheduler::CueInNaNSeconds.new().throw(),
$value
)
)

0 comments on commit 9b46cb9

Please sign in to comment.
You can’t perform that action at this time.