Padre::Task(3) User Contributed Perl Documentation Padre::Task(3)NAMEPadre::Task - Padre Task API 2.0
DESCRIPTION
The Padre Task API implements support for background and parallel
execution of code in the Padre IDE, and is based on the CPAN Process
API.
A Task Class is a class that completely encapsulates a single unit of
work, describing not only the work to be done, but also how the unit of
work is created, how is serialised for transport, and any
initialisation or cleanup work needs to be done.
A Task is a single self-contained unit of work, and is implemented as a
single instance of a particular Task Class.
The lifecycle of a Task object
From the perspective of a task author, the execution of a task will
occur in four distinct phases.
1. Construction
The creation of a task is always done completely independantly of its
execution. Typically this is done via the "new" method, or something
that calls it.
This separate construction step allows validation of parameters in
advance, as well as allowing bulk task pre-generation and advanced task
management functionality such as prioritisation, queueing, throttling
and load-balancing of tasks.
2. Preparation
Once a task has been constructed, an arbitrarily long time may pass
before the code is actually run (if it is ever run at all).
If the actual execution of the task will result in certain work being
done in the parent thread, this work cannot be done in the constructor.
And once created as an object, no futher task code will be called until
the task is ready for execution.
To give the author a chance to allow for any problems that may occur as
a result of this delay, the Task API provides a preparation phase for
the task via the "prepare" method.
This preparation code is run in the parent thread once the task has
been prioritised, has a worker allocated to it, and has been
encapsulated in its Padre::TaskHandle, but before the object is
serialised for transport into the thread.
A task can use this preparation phase to detach from non-serialisable
resources in the object such as database handles, to copy any
interesting parent state late rather than early, or decide on a last-
second self-abort.
Once the preparation phase is completed the task will be serialised,
transported into assigned worker thread and then executed immediately.
Because it will execute in the parent thead, the rest of the Padre
instance is available for use if needed, but the preparation code
should run quickly and must not block.
3. Execution
The main phase of the task is where the CPU-intensive or blocking code
can be safely run. It is run inside a worker thread in the background,
without impacting on the performance of the parent thread.
However, the task execution phase must be entirely self-contained.
The worker threads not only do not have access to the Padre IDE
variable structure, but most Padre classes (including heavily used
modules such as Padre::Current) will not be loaded at all in the worker
thread.
Any output that needs to be transported back to the parent should be
stored in the object somewhere. When the cleanup phase is run, these
values will be available automatically in the parent.
4. Cleanup
TO BE COMPLETED
SEE ALSO
Padre, Process
COPYRIGHT
Copyright 2008-2011 The Padre development team as listed in Padre.pm.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl 5 itself.
The full text of the license can be found in the LICENSE file included
with this module.
perl v5.14.1 2011-06-18 Padre::Task(3)