1. # Scheduler that always does things immediately, on the current thread.
  2. my class CurrentThreadScheduler does Scheduler {
  3. method handle_uncaught($exception) {
  4. $exception.throw
  5. }
  6. method cue(&code, :$at, :$in, :$every, :$times = 1, :&catch is copy ) {
  7. die "Cannot specify :at and :in at the same time"
  8. if $at.defined and $in.defined;
  9. die "Cannot specify :every and :times at the same time"
  10. if $every.defined and $times > 1;
  11. die "Cannot specify :every in {self.^name}"
  12. if $every;
  13. my $delay = $at ?? $at - now !! $in;
  14. sleep $delay if $delay;
  15. &catch //=
  16. self.uncaught_handler // -> $ex { self.handle_uncaught($ex) };
  17. for 1 .. $times {
  18. code();
  19. CATCH { default { catch($_) } };
  20. }
  21. class { method cancel() {} }
  22. }
  23. method loads(--> 0) { }
  24. }