Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Document Scheduler, ThreadPoolScheduler and CurrentThreadScheduler
  • Loading branch information
moritz committed Feb 26, 2015
1 parent 5b89eac commit 89f2ac4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 1 deletion.
1 change: 0 additions & 1 deletion WANTED
Expand Up @@ -16,7 +16,6 @@ Tutorials:

API docs:
* MOP
* Scheduler
* KeyReducer

Builtins:
12 changes: 12 additions & 0 deletions lib/Type/CurrentThreadScheduler.pod
@@ -0,0 +1,12 @@
=begin pod
=TITLE class CurrentThreadScheduler
=SUBTITLE A simple scheduler that blockingly executes code on the current thread
class CurrentThreadScheduler does Scheduler { ... }
C<CurrentThreadScheduler> executes tasks on the current threads. This means
that L<#method cue> blocks until the code has finished executing.
=end pod
47 changes: 47 additions & 0 deletions lib/Type/Scheduler.pod
@@ -0,0 +1,47 @@
=begin pod
=TITLE role Scheduler
=SUBTITLE Common roles for (thread/task) schedulers
role Scheduler {
has &.uncaught_handler is rw
}
Common role for schedulers. A scheduler is a piece of code that determines
which resources to use to run which task, and when.
Some operations for example on L<Proc::Async>, L<Promise|/type/Promise>,
L<Supply|/type/Supply> allow you to specify a scheduler explicitly; they
generally expect those schedulers to follow the interface defined by
C<Scheduler>
=head1 Methods
=head2 method uncaught_handler
method uncaught_handler() is rew
RW-Accessor for the handler that is caught for uncaught exceptions from the
code that is being scheduled and run.
=head2 method cue
method cue(:&code, Instant :$at, :$in, :$every, :$times = 1; :&catch)
Schedules a callable (C<&code>) for execution. The adverbs control when how
and the code is run:
C<$at> can be an L<Instant|/type/Instant> before which the code won't be run.
Alternatively C<$in> is the number of seconds (possibly fractional) to wait
before running the code.
If C<$every> is specified, it is interpreted as the number of seconds
(possibly fractional) to wait before re-executing the code.
C<$times> tells the scheduler how many times to run the code.
C<&catch> is called with the L<Exception|/type/Exception> as its sole argument
if C<&code> dies.
=end pod
23 changes: 23 additions & 0 deletions lib/Type/ThreadPoolScheduler.pod
@@ -0,0 +1,23 @@
=begin pod
=TITLE class ThreadPoolScheduler
=SUBTITLE Scheduler that distributes work among a pool of threads
class ThreadPoolScheduler does Scheduler { ... }
The C<ThreadPoolScheduler> has a range of number of threads that it maintains,
and it distributes work among those threads. When the upper limit of threads
isn't reached yet, and there is work pending, it spawns new threads to handle
the work.
=head1 Methods
=head2 new
method new(Int :$initial_threads = 0, Int :$max_threads=16)
Creates a new C<ThreadPoolScheduler> object with the given range of threads to
maintain.
=end pod

0 comments on commit 89f2ac4

Please sign in to comment.