Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Document Scheduler, ThreadPoolScheduler and CurrentThreadScheduler
- Loading branch information
Showing
4 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,6 @@ Tutorials: | |
|
|
||
| API docs: | ||
| * MOP | ||
| * Scheduler | ||
| * KeyReducer | ||
|
|
||
| Builtins: | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |