class ThreadPoolScheduler

Scheduler that distributes work among a pool of threads

class ThreadPoolScheduler does Scheduler {}

The 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.

Methods

new

method new(Int :$initial_threads = 0Int :$max_threads=16)

Creates a new ThreadPoolScheduler object with the given range of threads to maintain.

Type Graph

Type relations for ThreadPoolScheduler
perl6-type-graph ThreadPoolScheduler ThreadPoolScheduler Any Any ThreadPoolScheduler->Any Scheduler Scheduler ThreadPoolScheduler->Scheduler Mu Mu Any->Mu

Stand-alone image: vector

Routines supplied by role Scheduler

ThreadPoolScheduler does role Scheduler, which provides the following routines:

(Scheduler) method uncaught_handler

method uncaught_handler() is rw

RW-Accessor for the handler that is caught for uncaught exceptions from the code that is being scheduled and run.

(Scheduler) method cue

method cue(:&codeInstant :$at:$in:$every:$times = 1:&catch)

Schedules a callable (&code) for execution. The adverbs control when and how the code is run:

$at can be an Instant before which the code won't be run. Alternatively $in is the number of seconds (possibly fractional) to wait before running the code. If $at is in the past or $in is negative, the delay is treated as zero. Implementations may equate to zero very small values (e.g. lower than 0.001s) of $in or result of $at - now.

If $every is specified, it is interpreted as the number of seconds (possibly fractional) to wait before re-executing the code. Implementations may treat too-small values as lowest resolution they support, possibly warning in such situations; e.g. treating 0.0001 as 0.001.

$times tells the scheduler how many times to run the code.

&catch is called with the Exception as its sole argument if &code dies.