Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add a CurrentThreadScheduler.
Always schedules things on the current thread. Useful for forcing
synchrony on things that default to asynchrony.
  • Loading branch information
jnthn committed Oct 31, 2013
1 parent 7409806 commit 15a4103
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/vm/jvm/core/Threading.pm
Expand Up @@ -234,6 +234,34 @@ my class ThreadPoolScheduler does Scheduler {
# This thread pool scheduler will be the default one.
$PROCESS::SCHEDULER = ThreadPoolScheduler.new();

# Scheduler that always does things immediately, on the current thread.
my class CurrentThreadScheduler does Scheduler {
method handle_uncaught($exception) {
$exception.throw
}

method schedule(&code) {
code()
}

method schedule_in(&code, $delay) {
sleep $delay;
code();
}

method schedule_every(&code, $interval, $delay = 0) {
sleep $delay;
loop {
code();
sleep $interval;
}
}

method outstanding() {
0
}
}

# A promise is a synchronization mechanism for a piece of work that will
# produce a single result (keeping the promise) or fail (breaking the
# promise).
Expand Down

0 comments on commit 15a4103

Please sign in to comment.