Process
represents the access to a lacy execution.
Process
can be used as access to application code that executes with
a time delay. This can be eighter file requests or time consuming algorithms
that have to be delayed to prevent player timeouts.
Any Process
implementation can be started with start.
Any Process
can send events defined in following interfaces:
ProcessStartListener, ProcessErrorListener,
ProcessFinishListener, ProcessPauseListener,
ProcessResumeListener, ProcessUpdateListener
To listen to the events implement one or more of the above interfaces and
add the listener with addListener
as listener to the Process
.
public function start()
Starts the execution of this process.
It is possible that the process finishes execution before returning the from this method, but it is also possible that it finishes after returning from this method. This rule exists to not loose unnecessary performance by simple accepting that every process has to be finished after this execution.
Problematic example:
class MyClass implements ProcessFinishListener {
private var processStarted:Boolean
public function MyClass(Void) {
processStarted = false;
}
public function doSomething(Void):Void {
var process:Process = new MyProcess();
process.start();
process.addListener(this);
processStarted = true;
}
public function onFinishProcess(process:Process):Void {
if (processStarted) {
// do something
processStarted = false;
} else {
// throw an error (will be called if the process finishes immediatly.
}
}
}
Any Process
is allowed to take arguments for its execution or
return a result of its execution.
(optiona) result for the start (implementation specific).
public function hasStarted(Void):Boolean
Flag if the process has been started.
true if the process has been started and isn't finish yet else false.
public function hasFinished(Void):Boolean
Returns true
if the process has been finished else false
.
A Process
can only be finished if it has been started with
start()
true
if the process has been finished else false
public function isPaused(Void):Boolean
Returns true
if the process has been started and has been paused.
A Process
is allowed to be paused, this indicates that the process
is actually waiting for something.
true
if the process has been started and has been paused
public function isRunning(Void):Boolean
Returns true
if the process has been started and is not paused.
A Process
is allowed to be paused, this indicates that the process
is actually not waiting for something.
true
if the process has been started and is not paused
public function getPercentage(Void):Number
Returns the percentage of execution
There are several possibilies of return values:
If the execution has not been started and the percentage will be
evaluateable for sure it will return 0
.
If the execution has been started and the percentage is evaluateable,
it returns the current amount of percentage from 0
- 100
.
If the execution has finished and the percentage was evaluateable, it
returns 100
.
In any other case it will return null
.
current percentage of execution
public function setParentProcess(process:Process):Void
Allows the integration and access to a process hierarchy.
process | Process that started the current process.
|
IllegalArgumentException | if the passed-in process has the current process within the parent process list or if the passed-in process is the same process as the current process. |
public function getParentProcess(Void):Process
Returns the parent Process
set with setParentProcess
.
parent process if available, else null
.
public function getErrors(Void):Array
Returns the occured errors published with onProcessError
during
exeuction of the Process
in an array.
all occured errors during the execution of the event
public function hasError(Void):Boolean
Checks if an error occured during execution of the Process
.
true
if an error occured, else false
public function getDuration(Void):Time
By using start()
it saves the start time of the execution of the process.
This method allows access to the total execution time of the process. The total execution time get evaluated by comparing start time with end time or (if the process has not finished yet) with the current time.
time difference between start time and finish time or current point
public function getEstimatedTotalTime(Void):Time
Evaluates the expected total time of execution.
If the Process
has been finished it returns the final total time
of the execution.
If the Process
has not been started it returns a estimated total
time of 0
.
estimated time difference between start and finish time
public function getEstimatedRestTime(Void):Time
Evaluates the expected rest time until the execution finishes.
If the Process
has been finished it returns 0
. If it
has not been started it returns null
.
estimated rest time of the execution of the process.